3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Aurora { public static $items = array(); public function __construct(){ $this->report(); $this->init(); } protected function init(){ ToroHook::add("404", function() { }); Toro::serve(array( "/:alpha" => array( "directory" => "page", "controller" => "Page", "action" => "view", "params" => array("page") ), "/:number" => array( "directory" => "page", "controller" => "Page", "action" => "number", "params" => array("page") ) )); } public static function run($handler = array(),$request_method = "any",$regex_matches){ if(!empty($handler)){ vardump($handler); } } } class Toro{ public static function serve($routes = array()) { $tokens = array( ":string" => "([a-zA-Z]+)", ":number" => "([0-9]+)", ":alpha" => "([a-zA-Z0-9-_]+)", ":any" => "(.*)" ); ToroHook::fire("before_request", compact("routes")); $request_method = strtolower($_SERVER["REQUEST_METHOD"]); $b = false; $uri = @explode("/", $_SERVER["REQUEST_URI"])[2]; $path_info = ((!empty($uri)) ? $path_info = "/".$uri : $path_info = "/"); $discovered_handler = null; $path_info = "/a" if (isset($routes[$path_info])) { $discovered_handler = $routes[$path_info]; $b = true; }else if ($routes) { foreach ($routes as $pattern => $handler) { if(preg_match("#^/?" . strtr($pattern , $tokens) . "/?$#", $path_info, $regex_matches)){ unset($regex_matches[0]); $match = $regex_matches; $discovered_handler = $handler; $b = true; } } } $handler_instance = null; if ($b) { if (self::is_xhr_request()) { header("Content-type: application/json"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $request_method .= "_xhr"; } if ($b) { ToroHook::fire("before_handler", compact("routes", "discovered_handler", "request_method", "regex_matches")); Aurora::run($discovered_handler,$request_method,$match); ToroHook::fire("after_handler", compact("routes", "discovered_handler", "request_method", "regex_matches", "result")); } else { ToroHook::fire("404", compact("routes", "discovered_handler", "request_method", "regex_matches")); } } else { ToroHook::fire("404", compact("routes", "discovered_handler", "request_method", "regex_matches")); } ToroHook::fire("after_request", compact("routes", "discovered_handler", "request_method", "regex_matches", "result")); } private static function is_xhr_request(){ return isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] === "XMLHttpRequest"; } } class ToroHook { private static $instance; private $hooks = array(); private function __construct() {} private function __clone() {} public static function add($hook_name, $fn){ $instance = self::get_instance(); $instance->hooks[$hook_name][] = $fn; } public static function fire($hook_name, $params = null){ $instance = self::get_instance(); if (isset($instance->hooks[$hook_name])) { foreach ($instance->hooks[$hook_name] as $fn) { call_user_func_array($fn, array(&$params)); } } } public static function get_instance(){ if (empty(self::$instance)) { self::$instance = new ToroHook(); } return self::$instance; } }
Output for 5.4.0 - 5.4.32
Parse error: syntax error, unexpected 'if' (T_IF) in /in/agIFZ on line 50
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/agIFZ on line 46
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/agIFZ on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/agIFZ on line 11
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/agIFZ on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/agIFZ on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/agIFZ on line 5
Process exited with code 255.