3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Router { public function serve($uri); } class FlatRouter implements Router { public function serve($uri) { // send()s instance of HTTP\Request, no return value echo 'Serving request: ', $uri, ' using ', __CLASS__; } } class NestedRouter implements Router { public function serve($uri) { // send()s instance of HTTP\Request, no return value echo 'Serving request: ', $uri, ' using ', __CLASS__; } } abstract class Application { protected static $instances = array(); private $properties = array(); protected static function getInstance() { return isset(self::$instances[$className = get_called_class()]) ? self::$instances[$className] : self::$instances[$className] = new static(); } private function __construct() { } public function __set($propertyName, $value) { $this->properties[$propertyName] = $value; } public function __get($propertyName) { return is_callable($this->properties[$propertyName]) ? $this->properties[$propertyName] = $this->properties[$propertyName]($this) : $this->properties[$propertyName]; } } abstract class WebApplication extends Application { protected $routerClassName = 'FlatRouter'; private function __construct() { $this->router = function ($application) { $routerClassName = $application->routerClassName; return new $routerClassName(); }; } public static function serve($uri) { $instance = static::getInstance(); $instance->router->serve($uri); } } final class FooBarWebApplication extends WebApplication { protected $routerClassName = 'NestedRouter'; } FooBarWebApplication::serve('http://foo.bar/path/to/resource');
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to private WebApplication::__construct() from scope Application in /in/HAgvq:28 Stack trace: #0 /in/HAgvq(55): Application::getInstance() #1 /in/HAgvq(66): WebApplication::serve('http://foo.bar/...') #2 {main} thrown in /in/HAgvq on line 28
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:
47.89 ms | 401 KiB | 8 Q