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 = []){ 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.60.0140.00718.18
8.3.50.0110.00821.21
8.3.40.0120.00318.54
8.3.30.0040.01420.36
8.3.20.0150.00420.27
8.3.10.0110.00420.96
8.3.00.0090.00922.57
8.2.180.0100.01016.50
8.2.170.0140.00722.96
8.2.160.0090.00922.08
8.2.150.0070.01624.18
8.2.140.0090.00924.66
8.2.130.0090.00026.16
8.2.120.0050.00320.63
8.2.110.0030.00619.16
8.2.100.0090.00317.72
8.2.90.0000.00819.10
8.2.80.0000.00817.97
8.2.70.0040.00417.25
8.2.60.0080.00017.80
8.2.50.0040.00418.07
8.2.40.0040.00418.21
8.2.30.0030.00619.38
8.2.20.0030.00517.67
8.2.10.0000.00817.76
8.2.00.0080.00017.62
8.1.280.0090.00625.92
8.1.270.0040.00423.99
8.1.260.0110.00426.35
8.1.250.0030.01328.09
8.1.240.0100.00022.34
8.1.230.0060.00721.15
8.1.220.0040.00418.77
8.1.210.0050.00319.13
8.1.200.0000.00917.48
8.1.190.0060.00317.40
8.1.180.0030.00618.10
8.1.170.0080.00018.59
8.1.160.0000.00718.80
8.1.150.0000.00718.63
8.1.140.0000.00717.40
8.1.130.0050.00317.74
8.1.120.0050.00217.41
8.1.110.0000.00717.36
8.1.100.0030.00517.32
8.1.90.0000.00717.30
8.1.80.0000.00817.46
8.1.70.0000.00717.38
8.1.60.0040.00817.48
8.1.50.0050.00317.45
8.1.40.0030.00517.50
8.1.30.0000.00717.53
8.1.20.0030.00517.62
8.1.10.0030.00617.36
8.1.00.0030.00517.30
8.0.300.0030.00619.93
8.0.290.0040.00416.93
8.0.280.0000.00718.32
8.0.270.0000.00717.24
8.0.260.0080.00316.67
8.0.250.0000.00716.90
8.0.240.0050.00316.87
8.0.230.0070.00016.91
8.0.220.0000.00716.88
8.0.210.0000.00716.71
8.0.200.0000.00716.87
8.0.190.0000.00816.86
8.0.180.0080.00016.89
8.0.170.0000.00816.91
8.0.160.0040.00416.78
8.0.150.0040.00416.80
8.0.140.0000.00716.79
8.0.130.0070.00013.23
8.0.120.0030.00516.84
8.0.110.0050.00316.75
8.0.100.0050.00216.87
8.0.90.0080.00016.78
8.0.80.0090.00616.79
8.0.70.0040.00416.95
8.0.60.0000.00816.86
8.0.50.0070.00016.78
8.0.30.0140.00516.91
8.0.20.0080.01017.40
8.0.10.0000.00816.79
8.0.00.0090.00816.79
7.4.330.0000.00516.81
7.4.320.0070.00016.48
7.4.300.0030.00316.46
7.4.290.0000.00716.55
7.4.280.0060.00316.41
7.4.270.0030.00516.43
7.4.260.0000.00513.16
7.4.250.0000.00916.42
7.4.240.0000.00716.47
7.4.230.0040.00416.38
7.4.220.0220.00316.63
7.4.210.0050.01016.48
7.4.200.0030.00316.64
7.4.190.0030.00316.59
7.4.160.0110.00616.24
7.4.150.0040.01317.40
7.4.140.0090.00917.86
7.4.130.0130.00716.43
7.4.120.0130.00816.35
7.4.110.0090.00916.30
7.4.100.0060.01616.50
7.4.90.0120.01216.57
7.4.80.0060.01219.39
7.4.70.0120.01116.29
7.4.60.0090.00916.32
7.4.50.0060.00316.32
7.4.40.0040.01122.77
7.4.30.0100.00716.25
7.4.10.0090.00914.66
7.4.00.0030.01414.94
7.3.330.0000.00513.25
7.3.320.0000.00513.04
7.3.310.0030.00316.28
7.3.300.0000.00716.32
7.3.290.0070.01016.16
7.3.280.0060.00916.22
7.3.270.0150.00717.40
7.3.260.0090.01118.24
7.3.250.0090.01216.22
7.3.240.0100.00716.39
7.3.230.0040.01316.39
7.3.210.0120.00416.29
7.3.200.0030.01619.39
7.3.190.0060.01016.48
7.3.180.0100.00616.45
7.3.170.0110.00716.27
7.3.160.0130.00316.40
7.3.130.0110.00714.68
7.3.120.0060.01014.59
7.3.110.0000.01414.45
7.3.100.0100.00714.91
7.3.90.0100.00314.96
7.3.80.0030.00614.88
7.3.70.0100.00314.85
7.3.60.0100.00014.65
7.3.50.0100.00314.72
7.3.40.0000.01614.74
7.3.30.0050.00314.71
7.3.20.0030.01316.34
7.3.10.0140.00016.56
7.3.00.0120.00316.47
7.2.330.0150.00316.46
7.2.320.0090.00916.59
7.2.310.0100.01016.26
7.2.300.0070.01016.50
7.2.290.0060.01216.63
7.2.260.0060.01214.70
7.2.250.0070.01015.05
7.2.240.0030.01014.47
7.2.230.0030.01314.76
7.2.220.0030.01414.57
7.2.210.0040.00415.07
7.2.200.0110.00714.64
7.2.190.0000.01514.51
7.2.180.0000.00914.68
7.2.170.0030.00614.75
7.2.160.0030.00614.75
7.2.150.0040.00816.88
7.2.140.0100.00616.52
7.2.130.0020.01216.36
7.2.120.0090.00616.70
7.2.110.0060.00816.65
7.2.100.0080.00516.80
7.2.90.0040.01116.67
7.2.80.0080.00616.78
7.2.70.0030.01016.66
7.2.60.0060.00816.55
7.2.50.0070.00616.39
7.2.40.0040.01016.72
7.2.30.0060.00816.63
7.2.20.0020.01216.63
7.2.10.0020.01216.59
7.2.00.0090.01117.42
7.1.330.0030.01015.72
7.1.320.0060.00815.71
7.1.310.0060.00915.50
7.1.300.0090.00315.66
7.1.290.0070.00715.67
7.1.280.0080.00615.63
7.1.270.0100.00315.63
7.1.260.0040.00815.59
7.1.250.0030.01015.51
7.1.240.0020.01215.63
7.1.230.0060.00515.46
7.1.220.0050.00615.57
7.1.210.0070.00515.63
7.1.200.0050.00815.43
7.1.190.0020.00715.65
7.1.180.0090.00315.59
7.1.170.0060.00615.55
7.1.160.0050.00515.40
7.1.150.0100.00415.38
7.1.140.0020.01115.63
7.1.130.0040.00715.45
7.1.120.0070.00715.54
7.1.110.0050.00915.62
7.1.100.0150.00516.03
7.1.90.0030.01015.49
7.1.80.0060.00615.47
7.1.70.0030.00815.97
7.1.60.0080.00816.82
7.1.50.0060.01015.99
7.1.40.0080.00315.53
7.1.30.0090.00515.61
7.1.20.0080.00515.33
7.1.10.0020.01015.40
7.1.00.0010.03117.79
7.0.330.0030.00915.33
7.0.320.0030.00815.06
7.0.310.0030.01115.18
7.0.300.0030.01015.21
7.0.290.0040.00615.24
7.0.280.0020.01115.19
7.0.270.0030.00715.10
7.0.260.0090.00315.04
7.0.250.0070.00415.33
7.0.240.0070.00715.33
7.0.230.0080.00515.01
7.0.220.0020.00915.31
7.0.210.0060.00615.32
7.0.200.0030.00815.62
7.0.190.0060.00615.11
7.0.180.0070.00515.38
7.0.170.0050.00415.17
7.0.160.0070.00715.19
7.0.150.0020.00815.02
7.0.140.0030.02917.35
7.0.130.0060.00815.16
7.0.120.0070.00615.23
7.0.110.0060.00515.17
7.0.100.0180.02816.74
7.0.90.0090.02916.78
7.0.80.0120.03116.78
7.0.70.0100.03016.72
7.0.60.0070.03116.74
7.0.50.0070.02816.96
7.0.40.0040.03515.49
7.0.30.0070.03015.56
7.0.20.0050.02815.47
7.0.10.0080.02915.54
7.0.00.0060.02815.59
5.6.400.0060.00914.12
5.6.390.0060.00314.33
5.6.380.0030.01214.01
5.6.370.0070.00614.43
5.6.360.0070.00514.29
5.6.350.0080.00314.14
5.6.340.0000.01014.33
5.6.330.0050.00814.08
5.6.320.0080.00314.15
5.6.310.0020.01214.11
5.6.300.0050.00714.04
5.6.290.0040.00914.13
5.6.280.0070.02916.63
5.6.270.0070.01014.07
5.6.260.0000.01214.25
5.6.250.0050.03216.29
5.6.240.0060.03216.35
5.6.230.0020.03516.36
5.6.220.0080.03216.32
5.6.210.0090.03416.24
5.6.200.0070.03216.54
5.6.190.0030.03416.44
5.6.180.0030.03416.27
5.6.170.0060.03016.43
5.6.160.0030.03116.38
5.6.150.0100.03016.47
5.6.140.0080.02416.52
5.6.130.0070.02316.58
5.6.120.0090.03016.44
5.6.110.0030.03416.45
5.6.100.0070.02916.63
5.6.90.0060.03416.43
5.6.80.0070.03116.23
5.6.70.0050.03116.24
5.6.60.0070.03016.23
5.6.50.0080.02316.04
5.6.40.0080.02516.16
5.6.30.0070.02216.13
5.6.20.0100.02516.29
5.6.10.0090.01916.08
5.6.00.0040.02216.13
5.5.380.0080.02715.26
5.5.370.0040.02815.12
5.5.360.0070.02715.23
5.5.350.0060.03415.28
5.5.340.0050.01815.34
5.5.330.0110.02215.33
5.5.320.0110.02315.43
5.5.310.0080.01815.41
5.5.300.0070.03015.41
5.5.290.0080.02815.33
5.5.280.0090.03015.44
5.5.270.0080.02715.32
5.5.260.0060.02015.27
5.5.250.0090.02915.35
5.5.240.0050.03315.07
5.5.230.0050.01715.16
5.5.220.0030.02215.14
5.5.210.0020.02915.12
5.5.200.0090.02015.18
5.5.190.0070.02615.12
5.5.180.0060.02115.12
5.5.170.0070.00312.48
5.5.160.0080.03115.02
5.5.150.0060.01515.06
5.5.140.0040.03215.10
5.5.130.0100.02615.21
5.5.120.0030.03315.10
5.5.110.0030.03215.02
5.5.100.0070.02815.05
5.5.90.0080.02815.04
5.5.80.0060.03115.06
5.5.70.0040.02615.04
5.5.60.0070.01615.15
5.5.50.0050.02215.10
5.5.40.0100.01315.04
5.5.30.0110.01515.11
5.5.20.0070.01915.01
5.5.10.0020.02315.14
5.5.00.0040.02114.99
5.4.450.0040.03113.80
5.4.440.0050.02313.79
5.4.430.0060.01613.77
5.4.420.0080.01513.82
5.4.410.0080.03213.80
5.4.400.0040.03013.68
5.4.390.0040.02913.62
5.4.380.0040.02813.66
5.4.370.0070.03013.74
5.4.360.0080.02713.70
5.4.350.0090.02413.62
5.4.340.0040.02013.69
5.4.330.0060.00510.95
5.4.320.0040.02013.70
5.4.310.0070.01313.72
5.4.300.0080.01813.59
5.4.290.0070.02613.75
5.4.280.0060.02613.68
5.4.270.0080.02813.73
5.4.260.0060.02713.73
5.4.250.0020.02013.60
5.4.240.0010.02713.73
5.4.230.0050.02513.64
5.4.220.0040.01813.80
5.4.210.0040.02813.71
5.4.200.0020.02513.73
5.4.190.0050.01913.56
5.4.180.0060.02113.72
5.4.170.0030.02613.66
5.4.160.0060.02713.55
5.4.150.0060.01713.75
5.4.140.0120.02512.83
5.4.130.0030.01612.69
5.4.120.0030.01812.77
5.4.110.0040.01912.87
5.4.100.0070.01312.81
5.4.90.0080.02412.67
5.4.80.0110.02012.85
5.4.70.0040.02712.74
5.4.60.0050.02412.78
5.4.50.0070.02012.73
5.4.40.0090.01212.85
5.4.30.0040.02212.85
5.4.20.0020.01712.76
5.4.10.0030.02012.83
5.4.00.0060.01512.55
5.3.290.0040.02512.15
5.3.280.0070.02311.97
5.3.270.0050.02112.02
5.3.260.0040.02312.05
5.3.250.0120.01212.05
5.3.240.0050.01511.90
5.3.230.0020.03212.05
5.3.220.0040.02911.88
5.3.210.0040.02811.97
5.3.200.0080.02311.99
5.3.190.0050.02612.06
5.3.180.0060.02611.97
5.3.170.0010.02111.96
5.3.160.0060.01412.00
5.3.150.0030.01712.09
5.3.140.0070.01812.07
5.3.130.0050.01712.02
5.3.120.0070.01511.99
5.3.110.0040.01612.11
5.3.100.0030.01711.84
5.3.90.0010.01711.78
5.3.80.0050.01311.84
5.3.70.0050.01311.85
5.3.60.0040.01411.87
5.3.50.0030.01511.77
5.3.40.0030.02411.69
5.3.30.0030.01511.81
5.3.20.0050.01511.77
5.3.10.0030.01411.55
5.3.00.0050.01411.64

preferences:
36.39 ms | 401 KiB | 5 Q