3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Services { protected $services = []; public function getService($id, callback $creator) { // Нет в кэше? Берём из creator'а // Возвращаем кэш } } class Framework extends Services { protected $instance = null; public function __construct() { // Что-то } public static function getInstance() { if (is_null(static::$instance)) { throw new \Exception('Не инициализировано'); } return static::$instance; } public static function getRouter() { return static::getInstance()->getService('framework.router', function() use ($something) { return new Router($something); }) } public static function init() { static::$instance = new static; } public function run() { // Маршрутизация => Контроллер => Выполнение Response } } class CMS extends Framework { public static function getModulesManager() { return static::getInstance()->getService('cms.modulesmanager', function() use ($a, $b, $c) { return new ModulesManager($a, $b, $c) } } public function run() { // Маршрутизация => Встроенные контроллеры/Модули => Выполнение Response } } // based on framework Framework::init() && Framework::run(); // based on CMS CMS::init() && CMS::run();
Output for 7.0.0
Parse error: syntax error, unexpected '}', expecting ';' in /in/Rggg2 on line 38
Process exited with code 255.
Output for 5.4.10 - 5.6.16
Parse error: syntax error, unexpected '}' in /in/Rggg2 on line 38
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Rggg2 on line 5
Process exited with code 255.