3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new StdClass; $obj->fn = function($arg) { return "Hello $arg"; }; echo $obj->fn->call($obj, 'World'); echo PHP_EOL; echo ($obj->fn)();
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Cannot bind closure to scope of internal class stdClass in /in/6RgpA on line 6 Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 0 passed in /in/6RgpA on line 8 and exactly 1 expected in /in/6RgpA:4 Stack trace: #0 /in/6RgpA(8): {closure}() #1 {main} thrown in /in/6RgpA on line 4
Process exited with code 255.
Output for 7.0.0 - 7.0.33
Warning: Cannot bind closure to scope of internal class stdClass in /in/6RgpA on line 6 Warning: Missing argument 1 for {closure}(), called in /in/6RgpA on line 8 and defined in /in/6RgpA on line 4 Notice: Undefined variable: arg in /in/6RgpA on line 4 Hello
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /in/6RgpA on line 8
Process exited with code 255.

preferences:
230.83 ms | 402 KiB | 330 Q