3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function decorate(callable $fn, callable $decorator) { return function() use ($fn, $decorator) { $d = $decorator(); $gen = $d(); if (is_array($gen->current())) { $arguments = $gen->current(); } else { $arguments = func_get_args(); } $gen->send(call_user_func_array($fn, $arguments)); }; } function foo() { throw new Exception("Error!"); } function catch_all_exceptions() { return function() { try { (yield ["foo" => "bar"]); } catch (\Exception $e) { echo "Caught Exception: $e\n"; } }; } $foo = decorate("foo", "catch_all_exceptions"); $foo();
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Exception: Error! in /in/VJdkl:21 Stack trace: #0 /in/VJdkl(15): foo('bar') #1 /in/VJdkl(36): {closure}() #2 {main} thrown in /in/VJdkl on line 21
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'Error!' in /in/VJdkl:21 Stack trace: #0 [internal function]: foo('bar') #1 /in/VJdkl(15): call_user_func_array('foo', Array) #2 /in/VJdkl(36): {closure}() #3 {main} thrown in /in/VJdkl on line 21
Process exited with code 255.
Output for 5.3.0 - 5.4.45
Parse error: syntax error, unexpected '[' in /in/VJdkl on line 28
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/VJdkl on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/VJdkl on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/VJdkl 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/VJdkl on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/VJdkl on line 3
Process exited with code 255.