stdClass and anonymous function
I can do this with anonymous function
$func = function() {
return "Hello World";
};
var_dump($func());
However, I cannot do this
$namespace->func = function() {
return "Hello World";
};
var_dump($namespace->func());
I will get this error
Call to undefined method stdClass
The workaround that I have discovered so far is to use another variable
$temp = $namespace->func;
var_dump($temp());
Is there a way that I can do it in one line?
No comments:
Post a Comment