We have an anonymous function in a stdclass object like 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.
}
anonymous function are instance of Closure class, but when I check it with instanceof keyword it doesn't return true. what's the problem?
Problem is in namespace I had to use \Closure instead of Closure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With