php closures: why the 'static' in the anonymous function declaration when binding to static class?
found the difference: you can't bind static closures to object, only change the object scope.
class foo { }
$cl = static function() { };
Closure::bind($cl, new foo); // PHP Warning: Cannot bind an instance to a static closure
Closure::bind($cl, null, 'foo') // you can change the closure scope
Static Closures, like any other static method, cannot access $this
.
Like any other method, a non-static Closure that does not access $this
will generally work in a static context.
As you've noticed, it doesn't really matter.
It's like using the static
keyword on a class method. You don't necessarily need it if you don't reference $this
within the method (though this does violate strict standards).
I suppose PHP can work out you mean the Closure
to access A
statically due to the null
2nd argument to bind()