Jek Jek - 1 year ago 137
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;

Answer Source

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+

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download