3v4l.org

run code in 300+ PHP versions simultaneously
<?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.5.24 - 5.5.30, 5.6.8 - 5.6.16
Parse error: syntax error, unexpected '}' in /in/Rggg2 on line 38
Process exited with code 255.

preferences:
157.57 ms | 1395 KiB | 24 Q