3v4l.org

run code in 300+ PHP versions simultaneously
<?php class sM { static private $_methods = array(); static public function addMethod($name, Closure $cb) { self::$_methods[$name] = $cb; } public function __call($name, array $args) { array_unshift($args, $this); return call_user_func_array(self::$_methods[$name], $args); } public function add($a, $b) { return $a + $b; } } foreach(array(10) as $base) { sM::addMethod('add'.$base, function($self, $number) use ($base) { return $self->add($number, $base); }); } $sM = new sM(); echo $sM->add10(1)."\n"; foreach(array(100) as $base) { sM::addMethod('add'.$base, function($self, $number) use ($base) { return $self->add($number, $base); }); } echo $sM->add100(1)."\n"; echo $sM->add1000(1)."\n";
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
11 101 Warning: Undefined array key "add1000" in /in/fFagD on line 15 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in /in/fFagD:15 Stack trace: #0 /in/fFagD(42): sM->__call('add1000', Array) #1 {main} thrown in /in/fFagD on line 15
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 11 101 Warning: Undefined array key "add1000" in /in/fFagD on line 15 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in /in/fFagD:15 Stack trace: #0 /in/fFagD(42): sM->__call('add1000', Array) #1 {main} thrown in /in/fFagD on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.9
11 101 Warning: Undefined array key "add1000" in /in/fFagD on line 15 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback, no array or string given in /in/fFagD:15 Stack trace: #0 /in/fFagD(42): sM->__call('add1000', Array) #1 {main} thrown in /in/fFagD on line 15
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
11 101 Notice: Undefined index: add1000 in /in/fFagD on line 15 Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /in/fFagD on line 15
Output for 7.3.32 - 7.3.33
11 101 Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /in/fFagD on line 15

preferences:
151.76 ms | 401 KiB | 161 Q