Close check screen

We have an anonymous function in stdclass object like the following code:

$std = new \stdclass();
$std->method = function(){echo "Hi I'm  instance of Closure.";};

echo get_class($std->method); // prints "Closure"

if ($std->method instanceof Closure) {
    echo "Happy Ending."; // This line never gets executed.
}

      

the anonymous function is an instance of the Closure class, but when I inspect it with a keyword instanceof

it doesn't return true. what is the problem?

+3
php anonymous-function


source to share


1 answer


Namespace problem I had to use \Closure

instead Closure

.



0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics