You can use __invoke()
:
// declare $namespace to be conform to strict standards
$namespace = new StdClass();
$namespace->func = function() {
return "Hello World";
};
var_dump($namespace->func->__invoke());
That's because even if a property func
exists which is a closure, PHP will not check if it is a closure and call it.