<?php class x { /* function foo() { echo __METHOD__.PHP_EOL; } */ } $object = new x(); $method = 'foo'; $callable = [$object, $method]; //$callable(1); // Call to undefined method stdClass::foo() // No check until execution $closure = fn (...$args) => $object->$method(...$args); //$closure(1); // Call to undefined method stdClass::foo() //Call to undefined method stdClass::foo() $closure = [$object, $method](...); //Failed to create closure from callable: class stdClass does not have a method "foo" Closure::fromCallable([$object, $method]);
You have javascript disabled. You will not be able to edit any code.