3v4l.org

run code in 300+ PHP versions simultaneously
<?php header('Content-type: text/plain'); $middleware = ['middle_a', 'middle_b', 'middle_c', 'middle_d', 'middle_e']; function middle_a($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } function middle_b($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } function middle_c($output, $next) { try { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } catch (Exception1 $ex) { echo __FUNCTION__ . ":after\n"; // echo __FUNCTION__ . " caught a `" . get_class($ex) . "` and throws a `Exception2`\n"; // throw new Exception2(-100); return -100; // return $next(-100); } } function middle_d($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } function middle_e($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } class Exception1 extends Exception {} class Exception2 extends Exception {} class Exception3 extends Exception {} function act($input) { echo __FUNCTION__ . ":start\n"; throw new Exception1; return $input; } $pipeline = function($input) { return act($input); }; foreach (array_reverse($middleware) as $cb) { $pipeline = function($input) use ($cb, $pipeline) { return $cb($input, $pipeline); }; } try { var_dump($pipeline(0)); } catch (\Exception $ex) { exit("App caught a `" . get_class($ex) . "`"); }
Output for git.master, git.master_jit, rfc.property-hooks
middle_a:before middle_b:before middle_c:before middle_d:before middle_e:before act:start middle_c:after middle_b:after middle_a:after int(-100)

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:
28.95 ms | 405 KiB | 5 Q