No Binding But With Original¶
<?php
class A {
public function method() { }
}
class B extends A {
public function method() { }
}
class C {
public function method() { }
}
class D { }
$fn = Closure::fromCallable([new A, 'method']);
$fn->call(new B); // error
$fn->call(new C); // error
$fn->call(new D); // error
?>
It is possible to change the underlying object of a closure. The new closure will be executed with the new object, with the same method.
On the other hand, it is not possible to call that closure on another class, even if that class has the same method, nor even if the class is a child of the original one. It must be the same original class.
See Also¶
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026