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($tmpUrl, 0, 1) == '/') { $tmpUrl = substr($tmpUrl, 1); } if (substr($tmpUrl, -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); echo "3243242342" print_r($resourceMatches); 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; } } $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_r($routeObj->getMethodList()); printf($routeObj->getUrl()); print_r($routeObj->getUrlTokenList()); printf($routeObj->getController()); printf($routeObj->getAction()); print_r($routeObj->getTokenParameterList()); print_r($routeObj->getResourceList()); print_r($routeObj->getResourceDetailList()); }
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.34
Parse error: syntax error, unexpected '.', expecting ',' or ';' in /in/0BR1Y on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '.', expecting ',' or ';' in /in/0BR1Y on line 4
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/0BR1Y on line 4
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_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/0BR1Y on line 4
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/0BR1Y on line 4
Process exited with code 255.

preferences:
225.46 ms | 1386 KiB | 124 Q