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); 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 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Creation of dynamic property Route::$httpUrl is deprecated in /in/lPlhf on line 19 Array ( [0] => GET ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => [:music_category] [1] => xml ) CategoryControllerxmlArray ( [0] => music_category ) Array ( ) Deprecated: Creation of dynamic property Route::$httpUrl is deprecated in /in/lPlhf on line 19 Array ( [0] => GET ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => [:music_category] [1] => json ) CategoryControllerjsonArray ( [0] => music_category ) Array ( ) Deprecated: Creation of dynamic property Route::$httpUrl is deprecated in /in/lPlhf on line 19 Array ( [0] => GET [1] => POST ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => xml ) temp_controllerxmlArray ( ) Array ( ) Deprecated: Creation of dynamic property Route::$httpUrl is deprecated in /in/lPlhf on line 19 Array ( [0] => GET [1] => POST ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => json ) temp_controllerjsonArray ( ) Array ( ) Deprecated: Creation of dynamic property Route::$httpUrl is deprecated in /in/lPlhf on line 19 Array ( [0] => GET [1] => POST ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => post [1] => [:music_category] [2] => {:data} [3] => xml ) CategoryControllerpostArray ( [0] => music_category ) Array ( )
Output for 8.1.0 - 8.1.28
Array ( [0] => GET ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => [:music_category] [1] => xml ) CategoryControllerxmlArray ( [0] => music_category ) Array ( ) Array ( [0] => GET ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => [:music_category] [1] => json ) CategoryControllerjsonArray ( [0] => music_category ) Array ( ) Array ( [0] => GET [1] => POST ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => xml ) temp_controllerxmlArray ( ) Array ( ) Array ( [0] => GET [1] => POST ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => json ) temp_controllerjsonArray ( ) Array ( ) Array ( [0] => GET [1] => POST ) Deprecated: printf(): Passing null to parameter #1 ($format) of type string is deprecated in /in/lPlhf on line 108 Array ( [0] => post [1] => [:music_category] [2] => {:data} [3] => xml ) CategoryControllerpostArray ( [0] => music_category ) Array ( )
Output for 5.6.7 - 5.6.21, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Array ( [0] => GET ) Array ( [0] => [:music_category] [1] => xml ) CategoryControllerxmlArray ( [0] => music_category ) Array ( ) Array ( [0] => GET ) Array ( [0] => [:music_category] [1] => json ) CategoryControllerjsonArray ( [0] => music_category ) Array ( ) Array ( [0] => GET [1] => POST ) Array ( [0] => xml ) temp_controllerxmlArray ( ) Array ( ) Array ( [0] => GET [1] => POST ) Array ( [0] => json ) temp_controllerjsonArray ( ) Array ( ) Array ( [0] => GET [1] => POST ) Array ( [0] => post [1] => [:music_category] [2] => {:data} [3] => xml ) CategoryControllerpostArray ( [0] => music_category ) Array ( )
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.45, 5.5.24 - 5.5.35
Parse error: syntax error, unexpected '.', expecting ',' or ';' in /in/lPlhf 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/lPlhf 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/lPlhf 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/lPlhf 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/lPlhf on line 4
Process exited with code 255.

preferences:
238.76 ms | 401 KiB | 340 Q