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); }

preferences:
27.4 ms | 404 KiB | 5 Q