3v4l.org

run code in 300+ PHP versions simultaneously
<?php // $a = new stdClass(); // $a->sum = function($a,$b){return $a + $b;}; // // var_dump($a->sum); // // echo ($a->sum)(3,5); // $b = (object)["sum" => function($a,$b){return $a + $b;}]; // var_dump(($b->sum)(1,2)); class A{ public $sum; function __construct(){ $this->sum = function($a, $b){ return $a + $b; }; } function __call($method,$args) { // var_dump($method,$args); return call_user_func_array($this->$method, $args); // var_dump($test,$this->$method); } } $a = new A(); var_dump($a->sum(1,2)); $a->sub = function($a, $b){ return $a- $b; }; var_dump($a->sub(10,5)); var_dump($a->multiply(10,5));
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
int(3) Deprecated: Creation of dynamic property A::$sub is deprecated in /in/1veYm on line 35 int(5) Warning: Undefined property: A::$multiply in /in/1veYm on line 26 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in /in/1veYm:26 Stack trace: #0 /in/1veYm(40): A->__call('multiply', Array) #1 {main} thrown in /in/1veYm on line 26
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 int(3) Deprecated: Creation of dynamic property A::$sub is deprecated in /in/1veYm on line 35 int(5) Warning: Undefined property: A::$multiply in /in/1veYm on line 26 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in /in/1veYm:26 Stack trace: #0 /in/1veYm(40): A->__call('multiply', Array) #1 {main} thrown in /in/1veYm on line 26
Process exited with code 255.
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.28
int(3) int(5) Warning: Undefined property: A::$multiply in /in/1veYm on line 26 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in /in/1veYm:26 Stack trace: #0 /in/1veYm(40): A->__call('multiply', Array) #1 {main} thrown in /in/1veYm on line 26
Process exited with code 255.
Output for 8.0.0 - 8.0.9
int(3) int(5) Warning: Undefined property: A::$multiply in /in/1veYm on line 26 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback, no array or string given in /in/1veYm:26 Stack trace: #0 /in/1veYm(40): A->__call('multiply', Array) #1 {main} thrown in /in/1veYm on line 26
Process exited with code 255.
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
int(3) int(5) Notice: Undefined property: A::$multiply in /in/1veYm on line 26 Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /in/1veYm on line 26 NULL
Output for 7.3.32 - 7.3.33
int(3) int(5) Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /in/1veYm on line 26 NULL

preferences:
224.96 ms | 401 KiB | 291 Q