3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Route { private $method, $path, $handler; public function __construct($method, $path, $handler) { $this->method = $method; $this->path = $path; $this->handler = $handler; } public function prepend($path) { $this->path = $path . $this->path; return $this; } } function route($method, $path, $handler) { return new Route($method, $path, $handler); } function group($path, $function) { foreach ($function() as $route) { yield $route->prepend($path); } } function get_routes() { $handler = 'doSomething'; yield route('GET', '/', $handler); yield route('GET', '/foo', $handler); yield from group('/bar', function () { yield route('GET', '/hello ', $handler); yield route('GET', '/world', $handler); }); } foreach (get_routes() as $route) { var_dump($route); }
Output for git.master, git.master_jit, rfc.property-hooks
object(Route)#3 (3) { ["method":"Route":private]=> string(3) "GET" ["path":"Route":private]=> string(1) "/" ["handler":"Route":private]=> string(11) "doSomething" } object(Route)#4 (3) { ["method":"Route":private]=> string(3) "GET" ["path":"Route":private]=> string(4) "/foo" ["handler":"Route":private]=> string(11) "doSomething" } Warning: Undefined variable $handler in /in/FONBK on line 41 object(Route)#8 (3) { ["method":"Route":private]=> string(3) "GET" ["path":"Route":private]=> string(11) "/bar/hello " ["handler":"Route":private]=> NULL } Warning: Undefined variable $handler in /in/FONBK on line 42 object(Route)#9 (3) { ["method":"Route":private]=> string(3) "GET" ["path":"Route":private]=> string(10) "/bar/world" ["handler":"Route":private]=> NULL }

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:
126.91 ms | 407 KiB | 5 Q