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();
?>
Solutions¶
Remove the static option on the closure.
Remove the call to
bind().
In previous PHP versions, this error message used to be Cannot bind an instance to a static closure.