3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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); print_r($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); });
based on s8RmD
Output for 7.1.0 - 7.2.0
Closure Object ( [this] => Closure Object ( [parameter] => Array ( [$app] => <required> [$dos] => <required> ) ) [parameter] => Array ( [$app] => <required> [$dos] => <required> ) ) Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /in/K8ajm on line 30 and exactly 2 expected in /in/K8ajm:50 Stack trace: #0 /in/K8ajm(30): {closure}(Object(Uno)) #1 /in/K8ajm(53): Container::_post('hi@Uno', Object(Closure)) #2 {main} thrown in /in/K8ajm on line 50
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Closure Object ( [this] => Closure Object ( [parameter] => Array ( [$app] => <required> [$dos] => <required> ) ) [parameter] => Array ( [$app] => <required> [$dos] => <required> ) ) Fatal error: Uncaught TypeError: Argument 2 passed to {closure}() must be an instance of Dos, none given, called in /in/K8ajm on line 30 and defined in /in/K8ajm:50 Stack trace: #0 /in/K8ajm(30): {closure}(Object(Uno)) #1 /in/K8ajm(53): Container::_post('hi@Uno', Object(Closure)) #2 {main} thrown in /in/K8ajm on line 50
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Closure Object ( [this] => Closure Object ( [parameter] => Array ( [$app] => <required> [$dos] => <required> ) ) [parameter] => Array ( [$app] => <required> [$dos] => <required> ) ) Catchable fatal error: Argument 2 passed to {closure}() must be an instance of Dos, none given in /in/K8ajm on line 50
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Fatal error: Call to undefined method Closure::bindTo() in /in/K8ajm on line 27
Process exited with code 255.