I am trying to call a PHP function via an array like so:
$x = (object) array(
"one" => "value",
"two" => "value2",
"three" => function() {
return "return_value";
}
);
echo($x->three());
From this I receive the error:
<b>Fatal error</b>: Call to undefined method stdClass::three()
I've searched a bit and cannot find any documentation on this, however I ran this through
php -l filename.php
which found no syntax errors.
I would like to know if what I'm trying to do is possible (end goal is to call a function with parameters from an array). Is anybody able to shed some light on this?
Thanks
Note, I have also tried:
function foo() {
return "bar";
}
$x = (object) array(
"foo" => foo
);
...
which leads to the same result.