3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace CW\Router; use CW\Errors\NiunException; class Route { public static $request; private static $param; private static $paramArr = array(); public static function run($route_rule = array()){ self::$request = $route_rule; $routes = self::matchURI(); self::_prepareParams($routes); self::_prepareRoute($routes['controller'], $routes['action']); } private static function matchURI($uri = null) { $uri = (!$uri) ? parse_url($_SERVER['REQUEST_URI']) : $uri; $uri = ($uri['path'] == '/') ? '/' : rtrim($uri['path'],'\/'); if(!empty(self::$request)) { $count=count(self::$request); for($i=0; $i<$count; ++$i) { foreach(self::$request[$i] as $k => $v) { if (is_array($v) and $k !== 'param') { self::$param = self::$request[$i]['param']; $v['request'] = preg_replace_callback('/\<(?<key>[0-9a-z_]+)\>/', 'self::_replacer', str_replace(")",")?", $v['request']) ); $rulleTemp = array_merge((array)self::$request[$i], (array)$v); if(($t = self::_reportRulle($rulleTemp, $uri))) return $t; } } } } else return array(); } private static function _replacer($matches) { if(isset(self::$param[$matches['key']])) { return "(?<".$matches['key'].">".self::$param[$matches['key']].")"; } else return "(?<".$matches['key'].">"."([^/]+)".")"; } private static function _reportRulle($ini_array, $uri) { if(is_array($ini_array) and $uri) { if(preg_match("#^".$ini_array['request']."$#", $uri, $match)){ $r = array_merge((array)$ini_array, (array)$match); foreach($r as $k => $v) if((int)$k OR $k == 'param' OR $k == 'request') unset($r[$k]); return $r; } } } /** * Preparing controller to be included. Checking is controller exists. * Creating new specific model instance. Creating controller instance. * * @param $controller string Controller name. * @param $method string Method name. */ static function _prepareRoute($controller, $action) { $controller_path = Application . $controller . '/' . $controller . 'Controller.php'; self::_checkControllerExists($controller_path); self::_createModelInstance($controller); self::_createInstance($controller, $action); } /** * Checks requested URL on params and id and if exists sets to the private vars. * * @param $routes array Requested URL. */ static function _prepareParams($routes) { if ((!empty($routes['lang']) && !empty($routes['pagination']) && !empty($routes['page'])) || !empty($routes['lang']) || !empty($routes['pagination']) || !empty($routes['page'])) { self::$paramArr['lang'] = $routes['lang']; self::$paramArr['pagination'] = $routes['pagination']; self::$paramArr['page'] = $routes['page']; } } /** * Checks is controller exists and inlcude it. * * @param $controller_path string Controller path. Used to include and controller. * @throws Exception */ static function _checkControllerExists($controller_path) { try { if (file_exists($controller_path)) { require_once $controller_path; } else { throw new NiunException; } } catch (NiunException $e) { echo $e->getMessage(); } } /** * Creating new instance that required by URL. * * @param $controller string Controller name. * @param $method string Method name. */ static function _createInstance($controller, $action) { $instance = new $controller; if (method_exists($instance, $action)) { $reflection = new \ReflectionMethod($instance, $action); if (!$reflection->isPublic()) { @header('Location: /'); } $instance->$action(self::$paramArr); } else { @header('Location: /'); } } /** * Creates instance of model by requested controller. * * @param $controller string Controller name. */ static function _createModelInstance($controller) { $model = Application . $controller . '/' . $controller . 'Model.php'; if(file_exists($model)) { require_once ($model); } } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.40.0070.01818.57
8.3.30.0130.00720.17
8.3.20.0110.00820.21
8.3.10.0170.00320.71
8.3.00.0060.00622.51
8.2.170.0070.00722.96
8.2.160.0100.00722.21
8.2.150.0140.00724.18
8.2.140.0050.00324.66
8.2.130.0150.00426.16
8.2.120.0080.00020.80
8.2.110.0000.00919.21
8.2.100.0040.00717.59
8.2.90.0000.00819.22
8.2.80.0040.00417.97
8.2.70.0060.00317.50
8.2.60.0040.00417.91
8.2.50.0050.00318.07
8.2.40.0000.00818.21
8.2.30.0030.00619.41
8.2.20.0000.00717.48
8.2.10.0030.00517.70
8.2.00.0040.00417.68
8.1.270.0000.00823.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00322.42
8.1.230.0100.00321.01
8.1.220.0040.00418.77
8.1.210.0030.00519.14
8.1.200.0000.00917.13
8.1.190.0060.00317.53
8.1.180.0040.00418.10
8.1.170.0050.00318.61
8.1.160.0040.00418.75
8.1.150.0070.00018.55
8.1.140.0040.00417.40
8.1.130.0000.00717.71
8.1.120.0030.00517.45
8.1.110.0040.00417.27
8.1.100.0040.00417.44
8.1.90.0030.00317.42
8.1.80.0000.00717.40
8.1.70.0070.00017.29
8.1.60.0030.00717.54
8.1.50.0000.00717.46
8.1.40.0090.00017.46
8.1.30.0080.00017.59
8.1.20.0030.00517.58
8.1.10.0000.00817.45
8.1.00.0000.00817.36
8.0.300.0080.00319.96
8.0.290.0040.00416.92
8.0.280.0030.00318.30
8.0.270.0000.00717.07
8.0.260.0060.00316.67
8.0.250.0000.00716.90
8.0.240.0060.00316.80
8.0.230.0000.00716.89
8.0.220.0030.00316.82
8.0.210.0000.00716.79
8.0.200.0000.00616.88
8.0.190.0030.00516.90
8.0.180.0070.00016.87
8.0.170.0000.00716.91
8.0.160.0000.00716.78
8.0.150.0070.00016.77
8.0.140.0000.00716.66
8.0.130.0060.00013.23
8.0.120.0040.00416.79
8.0.110.0020.00516.78
8.0.100.0050.00316.78
8.0.90.0040.00416.87
8.0.80.0060.01216.82
8.0.70.0040.00416.73
8.0.60.0000.00716.84
8.0.50.0070.00016.87
8.0.30.0090.01017.07
8.0.20.0070.01217.40
8.0.10.0040.00416.84
8.0.00.0110.01116.61
7.4.330.0050.00016.73
7.4.320.0050.00216.47
7.4.300.0040.00416.45
7.4.290.0000.00716.54
7.4.280.0080.00016.47
7.4.270.0080.00016.38
7.4.260.0030.00313.21
7.4.250.0040.00416.38
7.4.240.0020.00616.49
7.4.230.0030.00316.35
7.4.220.0120.00616.34
7.4.210.0050.01116.58
7.4.200.0000.00716.33
7.4.190.0030.00316.63
7.4.160.0030.01416.50
7.4.150.0100.01017.40
7.4.140.0090.00717.86
7.4.130.0070.01016.51
7.4.120.0140.00616.40
7.4.110.0070.01316.47
7.4.100.0140.00316.43
7.4.90.0130.00516.38
7.4.80.0090.00919.39
7.4.70.0080.00816.34
7.4.60.0180.00616.40
7.4.50.0080.00016.25
7.4.40.0120.00322.77
7.4.30.0030.01416.48
7.4.00.0100.00714.98
7.3.330.0060.00013.26
7.3.320.0000.00513.24
7.3.310.0040.00416.19
7.3.300.0030.00316.25
7.3.290.0060.00816.25
7.3.280.0080.00716.25
7.3.270.0170.00017.40
7.3.260.0070.01418.24
7.3.250.0140.00716.37
7.3.240.0100.00716.23
7.3.230.0090.00916.39
7.3.210.0060.01016.45
7.3.200.0030.01319.39
7.3.190.0090.00916.37
7.3.180.0090.00616.29
7.3.170.0160.00016.29
7.3.160.0080.00816.43
7.3.120.0100.00314.69
7.2.330.0110.00616.21
7.2.320.0110.01116.57
7.2.310.0000.02316.63
7.2.300.0110.00916.35
7.2.290.0050.01116.22
7.2.00.0300.00719.34
7.1.100.0250.00417.14
7.1.70.0060.00917.00
7.1.60.0100.00719.17
7.1.50.0080.01516.98
7.1.00.0070.06322.39
7.0.200.0050.00516.66
7.0.140.0070.07022.07
7.0.100.0130.07319.99
7.0.90.0230.04720.07
7.0.80.0000.05020.18
7.0.70.0030.08320.18
7.0.60.0030.06320.00
7.0.50.0170.08320.43
7.0.40.0070.07320.12
7.0.30.0030.08320.04
7.0.20.0100.04320.11
7.0.10.0070.08020.18
7.0.00.0100.04320.06
5.6.280.0130.06321.11
5.6.250.0130.07020.81
5.6.240.0000.09020.80
5.6.230.0030.05720.73
5.6.220.0130.07320.66
5.6.210.0100.03320.59
5.6.200.0000.04321.04
5.6.190.0070.04021.10
5.6.180.0070.06721.12
5.6.170.0100.07721.06
5.6.160.0100.03720.99
5.6.150.0100.04321.11
5.6.140.0100.08321.08
5.6.130.0100.08321.18
5.6.120.0130.07721.13
5.6.110.0070.04721.12
5.6.100.0100.07721.11
5.6.90.0070.08321.03
5.6.80.0030.04020.48
5.6.70.0030.08320.56
5.6.60.0070.04720.49
5.6.50.0100.06720.38
5.6.40.0100.07020.51
5.6.30.0100.08020.46
5.6.20.0070.04020.46
5.6.10.0170.03020.45
5.6.00.0030.05020.29
5.5.380.0100.07320.55
5.5.370.0200.06320.38
5.5.360.0030.09020.44
5.5.350.0100.04020.37
5.5.340.0170.07320.78
5.5.330.0100.04720.92
5.5.320.0100.07720.93
5.5.310.0070.07020.94
5.5.300.0100.07020.92
5.5.290.0070.08320.87
5.5.280.0100.07320.81
5.5.270.0100.06720.92
5.5.260.0070.07020.68
5.5.250.0130.06320.49
5.5.240.0100.03320.34
5.5.230.0070.07020.22
5.5.220.0070.05320.05
5.5.210.0070.06320.23
5.5.200.0030.04720.23
5.5.190.0130.06720.30
5.5.180.0170.07020.23
5.5.160.0030.05020.27
5.5.150.0100.07720.27
5.5.140.0000.05020.24
5.5.130.0030.08320.32
5.5.120.0100.06320.15
5.5.110.0070.04720.27
5.5.100.0100.07720.11
5.5.90.0030.08020.20
5.5.80.0130.03720.11
5.5.70.0070.07320.21
5.5.60.0070.08019.97
5.5.50.0130.06020.11
5.5.40.0000.08320.18
5.5.30.0030.05020.09
5.5.20.0130.05320.12
5.5.10.0070.08320.08
5.5.00.0070.05720.09
5.4.450.0130.07319.37
5.4.440.0070.07719.38
5.4.430.0000.05319.22
5.4.420.0070.04719.20
5.4.410.0100.03319.33
5.4.400.0030.04019.16
5.4.390.0100.04719.13
5.4.380.0100.07718.91
5.4.370.0170.06019.05
5.4.360.0130.05719.13
5.4.350.0070.08018.88
5.4.340.0030.07019.21
5.4.320.0000.08319.06
5.4.310.0070.04719.07
5.4.300.0070.07319.16
5.4.290.0030.05719.05
5.4.280.0070.04319.16
5.4.270.0030.04018.88
5.4.260.0030.04719.18
5.4.250.0100.07319.20
5.4.240.0100.06719.16
5.4.230.0070.04019.03
5.4.220.0070.07719.13
5.4.210.0070.04319.13
5.4.200.0100.07718.94
5.4.190.0030.07319.15
5.4.180.0000.04719.22
5.4.170.0070.03719.04
5.4.160.0030.07318.88
5.4.150.0130.06318.90
5.4.140.0100.07016.36
5.4.130.0030.07016.45
5.4.120.0000.06316.27
5.4.110.0130.06316.46
5.4.100.0030.07016.39
5.4.90.0030.05716.47
5.4.80.0100.05716.34
5.4.70.0130.06316.38
5.4.60.0030.05016.29
5.4.50.0100.05716.47
5.4.40.0100.07016.51
5.4.30.0000.04316.37
5.4.20.0070.07716.40
5.4.10.0030.06316.50
5.4.00.0030.07015.96
5.3.290.0070.07714.64
5.3.280.0100.05714.60
5.3.270.0170.06714.64
5.3.260.0030.07314.68
5.3.250.0200.05714.67
5.3.240.0070.07714.63
5.3.230.0100.05714.64
5.3.220.0030.06714.55
5.3.210.0100.07014.59
5.3.200.0030.07314.64
5.3.190.0130.07014.74
5.3.180.0100.05714.67
5.3.170.0100.07014.71
5.3.160.0130.06714.69
5.3.150.0030.08014.59
5.3.140.0030.07314.73
5.3.130.0070.07714.53
5.3.120.0170.06714.57
5.3.110.0100.03714.66
5.3.100.0070.07714.23
5.3.90.0070.07014.20
5.3.80.0070.06014.13
5.3.70.0100.04014.00
5.3.60.0030.03714.06
5.3.50.0030.03713.91
5.3.40.0000.04713.93
5.3.30.0030.06313.95
5.3.20.0030.07313.86
5.3.10.0030.07313.66
5.3.00.0030.08713.61

preferences:
40.14 ms | 400 KiB | 5 Q