3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Dos{ function __construct(){ return 888888; } } class Container{ public static function _post($campo = 0, $callback = false) { list($post_key, $class) = explode('@', $campo); if (!empty($_POST)) { foreach (filter_var_array($_POST, FILTER_SANITIZE_ENCODED) as $key => $val) { if ($key == $post_key && empty($callback)) { return $val; } if ($key == $post_key && is_callable($callback)) { $oj = $callback->bindTo($callback); var_dump($oj); $obj = (class_exists($class)) ? new $class() : ""; (class_exists($class)) ? call_user_func($callback, $obj) : call_user_func($callback); } } } return false; } } class Uno{ public $uno = 1; function __construct(){ return 123; } } $_POST['hi'] = true; Container::_post('hi@Uno', function($app,Dos $dos){ var_dump($dos); });
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
object(Closure)#2 (2) { ["this"]=> object(Closure)#1 (1) { ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /in/s8RmD on line 30 and exactly 2 expected in /in/s8RmD:50 Stack trace: #0 /in/s8RmD(30): {closure}(Object(Uno)) #1 /in/s8RmD(50): Container::_post('hi@Uno', Object(Closure)) #2 {main} thrown in /in/s8RmD on line 50
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 object(Closure)#2 (2) { ["this"]=> object(Closure)#1 (1) { ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /in/s8RmD on line 30 and exactly 2 expected in /in/s8RmD:50 Stack trace: #0 /in/s8RmD(30): {closure}(Object(Uno)) #1 /in/s8RmD(50): Container::_post('hi@Uno', Object(Closure)) #2 {main} thrown in /in/s8RmD on line 50
Process exited with code 255.
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
object(Closure)#2 (2) { ["this"]=> object(Closure)#1 (1) { ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /in/s8RmD on line 30 and exactly 2 expected in /in/s8RmD:50 Stack trace: #0 /in/s8RmD(30): {closure}(Object(Uno)) #1 /in/s8RmD(53): Container::_post('hi@Uno', Object(Closure)) #2 {main} thrown in /in/s8RmD on line 50
Process exited with code 255.
Output for 7.0.0 - 7.0.33
object(Closure)#2 (2) { ["this"]=> object(Closure)#1 (1) { ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } Fatal error: Uncaught TypeError: Argument 2 passed to {closure}() must be an instance of Dos, none given, called in /in/s8RmD on line 30 and defined in /in/s8RmD:50 Stack trace: #0 /in/s8RmD(30): {closure}(Object(Uno)) #1 /in/s8RmD(53): Container::_post('hi@Uno', Object(Closure)) #2 {main} thrown in /in/s8RmD on line 50
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
object(Closure)#2 (2) { ["this"]=> object(Closure)#1 (1) { ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } ["parameter"]=> array(2) { ["$app"]=> string(10) "<required>" ["$dos"]=> string(10) "<required>" } } Catchable fatal error: Argument 2 passed to {closure}() must be an instance of Dos, none given in /in/s8RmD on line 50
Process exited with code 255.

preferences:
238.71 ms | 402 KiB | 330 Q