3v4l.org

run code in 500+ PHP versions simultaneously
<?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]);
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
Fatal error: Uncaught Error: Call to undefined method x::foo() in /in/tRUT3:22 Stack trace: #0 {main} thrown in /in/tRUT3 on line 22
Process exited with code 255.

preferences:
38.31 ms | 868 KiB | 4 Q