3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decorate(callable $fn, callable $decorator) { $wrapper = $decorator($fn); return function() use ($wrapper) { $returnValue = $wrapper(); return $returnValue; }; } 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"; call_user_func_array($fn, func_get_args()); }; } $bar = decorate(function() { echo "Hello\n"; }, "once"); $bar(); $bar(); $foo = decorate(decorate("foo", "catch_all_exceptions"), "do_something_before"); var_dump($foo("bar"));
Output for git.master, git.master_jit, rfc.property-hooks
Hello Before! Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 0 passed in /in/tIGFu on line 22 and exactly 1 expected in /in/tIGFu:13 Stack trace: #0 /in/tIGFu(22): foo() #1 /in/tIGFu(8): {closure}() #2 /in/tIGFu(47): {closure}() #3 /in/tIGFu(8): {closure}() #4 /in/tIGFu(56): {closure}('bar') #5 {main} thrown in /in/tIGFu on line 13
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
62.95 ms | 401 KiB | 8 Q