Cannot bind an instance to a static closure
Description
The Closure::bind() method gives the scope of execution of a closure. And a static closure uses no scope, so the bind() method fails.
Example
<?php
$closure = static function () { return __METHOD__;};
$closure->bindTo(new Stdclass());
$closure();
?>
Alternatives
- Remove the static option on the closure.
- Remove the call to
bind().
Related error messages
In more recent PHP versions, this error message is now :ref:cannot-bind-an-instance-to-a-static-closure,-this-will-be-an-error-in-php-9.