3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function decorate(callable $fn, array $decorators) { foreach ($decorators as $d) { $wrapper = $d($fn); $fn = $wrapper; } return $wrapper; } function foo($bar) { throw new Exception("Error $bar!"); } function catch_all_exceptions(callable $fn) { return function() use ($fn) { try { return call_user_func_array($fn, func_get_args()); } catch (\Exception $e) { echo "catch_all_exceptions: Caught Exception: $e\n"; } }; } function once(callable $fn) { return function() use ($fn) { static $return; static $called = false; if (!$called) { $return = call_user_func_array($fn, func_get_args()); $called = true; } return $return; }; } function do_something_before(callable $fn) { return function() use ($fn) { echo "Before!\n"; return call_user_func_array($fn, func_get_args()); }; } $bar = decorate(function() { echo "Hello\n"; }, "once"); $bar(); $bar(); $bar(); $foo = decorate("foo", ["catch_all_exceptions", "do_something_before"]); var_dump($foo("bar"));
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught TypeError: Argument 2 passed to decorate() must be of the type array, string given, called in /in/HR1od on line 51 and defined in /in/HR1od:3 Stack trace: #0 /in/HR1od(51): decorate(Object(Closure), 'once') #1 {main} thrown in /in/HR1od on line 3
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Catchable fatal error: Argument 2 passed to decorate() must be of the type array, string given, called in /in/HR1od on line 51 and defined in /in/HR1od on line 3
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/HR1od on line 56
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/HR1od on line 20
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/HR1od on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/HR1od on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting ')' in /in/HR1od on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/HR1od on line 3
Process exited with code 255.