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(); } // Forward all throwed Exceptions try { $gen->send(call_user_func_array($fn, $arguments)); } catch (\Exception $e) { $gen->throw($e); } }; } function foo($bar) { throw new Exception("Error $bar!"); } function catch_all_exceptions() { return function() { try { (yield); } catch (\Exception $e) { echo "Caught Exception: $e\n"; } }; } function do_something_before() { return function() { echo "Before!\n"; }; } $foo = decorate(decorate("foo", "catch_all_exceptions"), "do_something_before"); $foo("bar");
Output for git.master, git.master_jit, rfc.property-hooks
Before! Fatal error: Uncaught Error: Call to a member function current() on null in /in/2jP1L:9 Stack trace: #0 /in/2jP1L(48): {closure}('bar') #1 {main} thrown in /in/2jP1L on line 9
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:
41.42 ms | 401 KiB | 8 Q