Cannot bind an instance to a static closure, this will be an error in PHP 9
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
- cannot-rebind-scope-of-closure-created-from-method,-this-will-be-an-error-in-php-9
- cannot-bind-method-%s::%s()-to-object-of-class-%s,-this-will-be-an-error-in-php-9
- cannot-rebind-scope-of-closure-created-from-function,-this-will-be-an-error-in-php-9
- cannot-unbind-$this-of-closure-using-$this,-this-will-be-an-error-in-php-9
In previous PHP versions, this error message used to be :ref:cannot-bind-an-instance-to-a-static-closure.