A closure defined in PHP may also contain a static modifier.
$f = function () { }; $g = static function () { };
Static closure cannot be bound using Closure::bind or Closure::bindTo and generates a warning.
$g = Closure::bind(static function () { }, new stdClass());
This is also the case of closures created by reflecting a static method with ReflectionMethod::getClosure .
class MyClass { public static function myStaticMethod() { } }
While it is annoying, it is acceptable; However, how to test static and non-static closure?
ReflectionMethod::isStatic seemed like this might work, but reasonably not like Closure::__invoke is an instance level and not static.
$f = static function () { };
In addition, checking ReflectionMethod::getClosureThis may generally work, since the static method must be unbound, however this does not cover closures defined outside the instance method, or the corner case of instance methods that were unbound.
class MyClass { public function myInstanceMethod() { } } $o = new MyClass();
So, to confirm, how do you determine if a closure is static (or, more specifically, bound) or not?
It seems that we should have ReflectionFunctionAbstract::isBindable or ReflectionMethod::isStatic navigate to ReflectionFunctionAbstract .