3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Route { //const RESOURCE_PATTERN = '/\[:(.*)\]/'; //const TOKEN_PARA_PATTERN = '/\{:(.*)\}/'; private methodList; private url; private urlTokenList; private urlTokenCount; private controller; private action; private tokenParameterList; private resourceList = array(); private resourceDetailList = array(); public function __construct($httpMethod, $httpUrl, $controller, $action) { $this->methodList = explode('|', $httpMethod); $this->httpUrl = $httpUrl; $this->controller = $controller; $this->action => $action; $this->parseURL($httpUrl); } public function parseURL($url) { $tmpUrl = $url; if (substr($requestURI, 0, 1) == '/') { $tmpUrl = substr($tmpUrl, 1); } if (substr($requestURI, -1) == '/') { $tmpUrl = substr($tmpUrl, 0, -1); } $this->urlTokenList = explode('/', $tmpUrl); $this->urlTokenCount = count($this->urlTokenList); foreach($this->urlTokenList as $token) { $isMatchedForResourcePattern = preg_match(self::RESOURCE_PATTERN, $token, $resourceMatches, PREG_OFFSET_CAPTURE); if ($isMatchedForResourcePattern === 1) { array_push($this->resourceList, $resourceMatches[1][0]); } $isMatchedForParaPattern = preg_match(self::TOKEN_PARA_PATTERN, $token, $paramMatches, PREG_OFFSET_CAPTURE); } } public function getMethodList() { return $this->methodList; } public function getUrl() { return $this->url; } public function getUrlTokenList() { return $this->urlTokenList; } public function getUrlTokenCount() { return $this->urlTokenCount; } public function getController() { return $this->controller; } public function getAction() { return $this->action; } public function getTokenParameterList() { return $this->tokenParameterList; } public function getResourceList() { return $this->resourceList; } public function getResourceDetailList() { return $this->resourceDetailList; } public function isMatched($url) { return 0; } } define( 'ROUTES', array( array('httpMethod' => 'GET', 'url' => '[:music_category]/xml', 'controller' => 'CategoryController', 'action' => 'xml'), array('httpMethod' => 'GET', 'url' => '[:music_category]/json', 'controller' => 'CategoryController', 'action' => 'json'), array('httpMethod' => 'GET|POST', 'url' => 'xml', 'controller' => 'temp_controller', 'action' => 'xml'); array('httpMethod' => 'GET|POST', 'url' => 'json', 'controller' => 'temp_controller', 'action' => 'json'); array('httpMethod' => 'GET|POST', 'url' => 'post/[:music_category]/{:data}/xml', 'controller' => 'CategoryController', 'action' => 'post'); ); ); foreach (ROUTES as $route) { $routeObj = new Route($route['httpMethod'], $route['url'], $route['controller'], $route['action']); print_f($routeObj->getMethodList()); print_f($routeObj->getUrl()); print_f($routeObj->getUrlTokenList()); print_f($routeObj->getController()); print_f($routeObj->getAction()); print_f($routeObj->getTokenParameterList()); print_f($routeObj->getResourceList()); print_f($routeObj->getResourceDetailList()); }
Output for 5.4.0 - 5.4.34
Parse error: syntax error, unexpected 'methodList' (T_STRING), expecting variable (T_VARIABLE) in /in/NFrcV on line 7
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/NFrcV on line 7
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE in /in/NFrcV on line 7
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/NFrcV on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NFrcV on line 7
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/NFrcV on line 7
Process exited with code 255.

preferences:
200.39 ms | 1395 KiB | 124 Q