3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new StdClass; $obj->fn = function($arg) { return "Hello $arg"; }; echo ($obj->fn)('World'); class Bla { public $fn; public $fn2; public function __construct($f){ $this->fn2 = $f; } } $bla = new Bla; $bla->fn = function($arg="Bu"){return "Hello lo $arg"; }; // can't do in class! echo ($bla->fn)('Wa'); $blah = new Bla(function(){ return "F!";}); echo ($bla->fn2)();
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.4, 8.3.6
Hello World Fatal error: Uncaught ArgumentCountError: Too few arguments to function Bla::__construct(), 0 passed in /in/bOkjT on line 15 and exactly 1 expected in /in/bOkjT:11 Stack trace: #0 /in/bOkjT(15): Bla->__construct() #1 {main} thrown in /in/bOkjT on line 11
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Hello World Fatal error: Uncaught ArgumentCountError: Too few arguments to function Bla::__construct(), 0 passed in /in/bOkjT on line 15 and exactly 1 expected in /in/bOkjT:11 Stack trace: #0 /in/bOkjT(15): Bla->__construct() #1 {main} thrown in /in/bOkjT on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Hello World Warning: Missing argument 1 for Bla::__construct(), called in /in/bOkjT on line 15 and defined in /in/bOkjT on line 11 Notice: Undefined variable: f in /in/bOkjT on line 12 Hello lo Wa Fatal error: Uncaught Error: Function name must be a string in /in/bOkjT:20 Stack trace: #0 {main} thrown in /in/bOkjT on line 20
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /in/bOkjT on line 5
Process exited with code 255.

preferences:
150.53 ms | 402 KiB | 225 Q