3v4l.org

run code in 300+ PHP versions simultaneously
<?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 5.3.0 - 5.3.20, 5.4.0 - 5.4.10
Parse error: syntax error, unexpected '{' in /in/ANtF0 on line 9
Process exited with code 255.

preferences:
163.02 ms | 1395 KiB | 39 Q