Cannot bind method %s::%s() to object of class %s

Description

This error is reported when a closure is called on an object which is not identical to the the type of the original object.

Example

<?php

class X {
    public function method() {    }
}

class Y { }

$closure = Closure::fromCallable([new X, 'method']);
$closure->call(new B);

?>

Literal Examples

  • Cannot bind method A::M() to object of class C

Solutions

  • Make sure the new object is of the same type as the original support one.