Jek Jek - 4 months ago 39
PHP Question

Give PHP function class object

Is it possible to call a function and supply it with a class? Something like:

function foo(class $class) {
// do something with the class
echo $class->id;

// calling the function
foo(class Bar {
// supplying the class
public $id, $username, $password, $time, $ip;


Your example is a little confusing but I think you are looking for an anonymous class:

function foo($class) {
    echo $class->id;

foo(new class {
    public $id;

Note that anonymous classes are available only for PHP 7+