3v4l.org

run code in 300+ PHP versions simultaneously
<?php class URI implements \ArrayAccess, \Iterator, \Countable, \JsonSerializable { const SCHEME = 0x01; const USER = 0x02; const PASS = 0x04; const HOST = 0x08; const PORT = 0x10; const PATH = 0x20; const QUERY = 0x40; const FRAGMENT = 0x80; // The private props and magic methods are only implemented like this to give type validation, // these are effectively public properties private $scheme; private $user; private $pass; private $host; private $port; private $path; private $query; private $fragment; // obviously these two properties would be handled internally in a native impl private static $constPropMap = [ self::SCHEME => 'scheme', self::USER => 'user', self::PASS => 'pass', self::HOST => 'host', self::PORT => 'port', self::PATH => 'path', self::QUERY => 'query', self::FRAGMENT => 'fragment', ]; private $iteratorCounter = self::SCHEME; private function validateScheme($value) { // in the generic URI syntax, only the format of the scheme is rigid return (bool) preg_match('/^[a-z][a-z0-9+.\-]*$/i', $value); } public function __construct($uri) { $parts = []; if (((string) $uri) !== '' && false === $parts = parse_url($uri)) { throw new \InvalidArgumentException('Invalid URI'); } foreach ($parts as $name => $value) { $this->__set($name, urldecode($value)); } } public function __get($name) { if (!in_array($name, self::$constPropMap)) { trigger_error('Undefined property: ' . __CLASS__ . '::$' . $name, E_USER_NOTICE); return null; } return $this->$name; } public function __set($name, $value) { if ($value === null) { $this->$name = null; } else if ($name === 'port') { $this->port = (int) $value; } else if ($name === 'query') { parse_str($value, $this->query); } else if (in_array($name, self::$constPropMap)) { if ($name === 'scheme' && !$this->validateScheme($value)) { throw new \InvalidArgumentException('Invalid URI scheme'); } $this->$name = (string) $value; } else { // because PHP allows expando properties on anything afaik :-( $this->$name = $value; } } public function __toString() { $result = ''; if (isset($this->scheme)) { $result = $this->scheme . ':'; } if (isset($this->host)) { $result .= '//'; if (isset($this->user)) { $result .= urlencode($this->user); if (isset($this->pass)) { $result .= ':' . urlencode($this->pass); } $result .= '@'; } $result .= urlencode($this->host); if (isset($this->port)) { $result .= ':' . $this->port; } } if (isset($this->path)) { $result .= urlencode($this->path); } if (!empty($this->query)) { $result .= '?' . http_build_query($this->query); } if (isset($this->fragment)) { $result .= '#' . urlencode($this->fragment); } return $result; } /* ArrayAccess */ public function offsetExists($name) { return isset($this->$name) || isset(self::$constPropMap[$name]); } public function offsetGet($name) { if (isset(self::$constPropMap[$name])) { return $this->__get(self::$constPropMap[$name]); } else { return $this->__get($name); } } public function offsetSet($name, $value) { if (isset(self::$constPropMap[$name])) { $this->__set(self::$constPropMap[$name], $value); } else { $this->__set($name, $value); } } public function offsetUnset($name) { if (isset(self::$constPropMap[$name])) { $this->__set(self::$constPropMap[$name], null); } else if (in_array($name, self::$constPropMap)) { $this->__set($name, null); } else { unset($this->$name); } } /* Iterator */ public function current() { return $this->{self::$constPropMap[$this->iteratorCounter]}; } public function key() { return self::$constPropMap[$this->iteratorCounter]; } public function next() { $this->iteratorCounter *= 2; } public function rewind() { $this->iteratorCounter = self::SCHEME; } public function valid() { return $this->iteratorCounter <= self::FRAGMENT; } /* Countable */ public function count() { $result = 0; foreach (self::$constPropMap as $const => $name) { if ($this->$name !== null) { $result++; } } return $result; } /* JsonSerializable */ public function jsonSerialize() { return $this->__toString(); } } $uri = new URI('http://www.google.com/'); $uri['query']['foo'] = '&bar'; echo $uri;

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.0210.00018.41
8.3.50.0090.01222.26
8.3.40.0140.00419.09
8.3.30.0090.00619.17
8.3.20.0040.00420.10
8.3.10.0050.00322.14
8.3.00.0050.00322.45
8.2.180.0060.01016.75
8.2.170.0060.01022.96
8.2.160.0060.01320.92
8.2.150.0030.00624.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0100.00019.32
8.2.110.0030.00721.05
8.2.100.0080.00418.16
8.2.90.0050.00318.41
8.2.80.0070.00418.28
8.2.70.0000.01018.00
8.2.60.0040.00417.88
8.2.50.0000.00817.88
8.2.40.0000.00819.73
8.2.30.0040.00418.05
8.2.20.0050.00317.95
8.2.10.0040.00419.68
8.2.00.0030.00617.90
8.1.280.0120.00325.92
8.1.270.0000.00823.91
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0030.00623.92
8.1.230.0120.00321.07
8.1.220.0000.00817.91
8.1.210.0090.00018.91
8.1.200.0090.00017.60
8.1.190.0050.00317.60
8.1.180.0030.00618.10
8.1.170.0000.00719.14
8.1.160.0000.00718.93
8.1.150.0080.00018.88
8.1.140.0020.00517.79
8.1.130.0030.00317.88
8.1.120.0070.00017.75
8.1.110.0000.00717.58
8.1.100.0000.00717.61
8.1.90.0030.00517.68
8.1.80.0040.00417.57
8.1.70.0000.00717.57
8.1.60.0000.00917.81
8.1.50.0080.00017.77
8.1.40.0040.00417.63
8.1.30.0040.00417.88
8.1.20.0000.00917.81
8.1.10.0030.00617.82
8.1.00.0030.00617.65
8.0.300.0050.00320.11
8.0.290.0040.00417.00
8.0.280.0040.00418.23
8.0.270.0070.00018.29
8.0.260.0000.00717.11
8.0.250.0000.00717.18
8.0.240.0040.00417.23
8.0.230.0000.00717.22
8.0.220.0030.00517.18
8.0.210.0030.00317.19
8.0.200.0000.00717.10
8.0.190.0080.00017.26
8.0.180.0030.00617.23
8.0.170.0030.00617.19
8.0.160.0040.00417.06
8.0.150.0070.00017.14
8.0.140.0020.00517.05
8.0.130.0000.00613.59
8.0.120.0030.00517.00
8.0.110.0040.00417.06
8.0.100.0000.00817.17
8.0.90.0030.00517.18
8.0.80.0070.01017.17
8.0.70.0030.00517.07
8.0.60.0000.00817.23
8.0.50.0000.00717.22
8.0.30.0130.01217.25
8.0.20.0140.00517.41
8.0.10.0040.00417.08
8.0.00.0110.00617.17
7.4.330.0050.00015.05
7.4.320.0000.00716.80
7.4.300.0060.00016.89
7.4.290.0000.00816.75
7.4.280.0030.00316.93
7.4.270.0030.00316.80
7.4.260.0000.00716.73
7.4.250.0050.00316.75
7.4.240.0040.00416.72
7.4.230.0030.00316.77
7.4.220.0100.00716.75
7.4.210.0090.00816.81
7.4.200.0030.00316.59
7.4.190.0000.00717.07
7.4.160.0030.01316.98
7.4.150.0120.00917.40
7.4.140.0120.00917.86
7.4.130.0090.01216.86
7.4.120.0080.01016.87
7.4.110.0160.00316.73
7.4.100.0070.01416.73
7.4.90.0090.00916.77
7.4.80.0040.01419.39
7.4.70.0030.01416.82
7.4.60.0060.00916.62
7.4.50.0030.00616.71
7.4.40.0000.01222.77
7.4.30.0090.00916.89
7.4.10.0070.01415.40
7.4.00.0070.01115.27
7.3.330.0050.00013.66
7.3.320.0050.00013.68
7.3.310.0000.00716.56
7.3.300.0040.00416.66
7.3.290.0150.00616.65
7.3.280.0100.00716.66
7.3.270.0030.01817.40
7.3.260.0120.00916.75
7.3.250.0120.00916.71
7.3.240.0070.01016.87
7.3.230.0120.00616.69
7.3.210.0120.01316.58
7.3.200.0160.00319.39
7.3.190.0080.00816.82
7.3.180.0100.00716.84
7.3.170.0090.00616.66
7.3.160.0120.00316.78
7.3.130.0000.01415.09
7.3.120.0070.01114.98
7.3.110.0060.01115.12
7.3.100.0080.00615.26
7.3.90.0050.00715.36
7.3.80.0020.01015.14
7.3.70.0040.00915.04
7.3.60.0040.00815.21
7.3.50.0070.00715.17
7.3.40.0070.00615.10
7.3.30.0030.01115.00
7.3.20.0080.00716.96
7.3.10.0080.00816.83
7.3.00.0060.00916.83
7.2.330.0140.00617.00
7.2.320.0170.00416.75
7.2.310.0120.01216.84
7.2.300.0090.00916.81
7.2.290.0070.01117.05
7.2.260.0120.00815.56
7.2.250.0090.01015.25
7.2.240.0090.00815.34
7.2.230.0010.01415.34
7.2.220.0060.00815.10
7.2.210.0070.00615.38
7.2.200.0060.00615.28
7.2.190.0050.00915.12
7.2.180.0070.00515.26
7.2.170.0040.01015.32
7.2.160.0040.01115.31
7.2.150.0070.00717.13
7.2.140.0070.00717.21
7.2.130.0050.01116.73
7.2.120.0100.00717.06
7.2.110.0080.00917.01
7.2.100.0120.00717.08
7.2.90.0110.00717.20
7.2.80.0050.01117.16
7.2.70.0070.00816.86
7.2.60.0100.00817.01
7.2.50.0130.00617.02
7.2.40.0080.00916.89
7.2.30.0120.00716.96
7.2.20.0060.01017.01
7.2.10.0090.01017.05
7.2.00.0050.01017.73
7.1.330.0100.00415.93
7.1.320.0080.00515.80
7.1.310.0070.00515.85
7.1.300.0070.00515.82
7.1.290.0040.01215.91
7.1.280.0070.00616.03
7.1.270.0050.00815.86
7.1.260.0020.00815.91
7.1.250.0090.00615.86
7.1.240.0060.00615.96
7.1.230.0030.01015.82
7.1.220.0080.00416.06
7.1.210.0030.00815.82
7.1.200.0110.00015.73
7.1.190.0060.00616.04
7.1.180.0070.01016.13
7.1.170.0000.01116.09
7.1.160.0030.01015.88
7.1.150.0070.00715.82
7.1.140.0090.00015.95
7.1.130.0060.00916.19
7.1.120.0060.00615.63
7.1.110.0000.01316.15
7.1.100.0060.00517.25
7.1.90.0070.00716.02
7.1.80.0100.00616.09
7.1.70.0040.00516.57
7.1.60.0000.02017.88
7.1.50.0110.01125.63
7.1.40.0070.00716.22
7.1.30.0040.00715.62
7.1.20.0080.00816.13
7.1.10.0100.00316.11
7.1.00.0070.04019.18
7.0.330.0030.00715.46
7.0.320.0100.00315.41
7.0.310.0030.01015.64
7.0.300.0030.01015.39
7.0.290.0080.00415.68
7.0.280.0040.00815.78
7.0.270.0070.00715.44
7.0.260.0000.00915.38
7.0.250.0030.01015.43
7.0.240.0030.00615.47
7.0.230.0000.01515.53
7.0.220.0110.00315.66
7.0.210.0040.01115.86
7.0.200.0100.00816.34
7.0.190.0040.00815.29
7.0.180.0070.00415.41
7.0.170.0060.00915.70
7.0.160.0090.00315.74
7.0.150.0040.00415.57
7.0.140.0040.03918.96
7.0.130.0000.00915.73
7.0.120.0070.00315.68
7.0.110.0090.03217.79
7.0.100.0070.02517.79
7.0.90.0120.02117.80
7.0.80.0100.03017.65
7.0.70.0050.03517.98
7.0.60.0120.03917.88
7.0.50.0050.04017.93
7.0.40.0070.04517.01
7.0.30.0180.01516.77
7.0.20.0050.04716.59
7.0.10.0120.04416.89
7.0.00.0110.04316.76
5.6.400.0030.00914.56
5.6.390.0030.00914.67
5.6.380.0100.00014.59
5.6.370.0060.00614.79
5.6.360.0060.00914.85
5.6.350.0080.00014.92
5.6.340.0000.01114.83
5.6.330.0000.00914.84
5.6.320.0070.00714.42
5.6.310.0030.01014.82
5.6.300.0030.01014.59
5.6.290.0040.00814.75
5.6.280.0060.03817.94
5.6.270.0100.00614.81
5.6.260.0130.00314.88
5.6.250.0060.02417.61
5.6.240.0120.02017.72
5.6.230.0030.02417.74
5.6.220.0030.04617.64
5.6.210.0050.04517.65
5.6.200.0070.04517.77
5.6.190.0080.04117.84
5.6.180.0060.03117.79
5.6.170.0080.04617.91
5.6.160.0050.04817.95
5.6.150.0080.04317.76
5.6.140.0050.03017.99
5.6.130.0110.03317.87
5.6.120.0080.04417.98
5.6.110.0020.05018.04
5.6.100.0050.04417.79
5.6.90.0060.04317.83
5.6.80.0080.04317.38
5.6.70.0110.03017.35
5.6.60.0060.02817.59
5.6.50.0080.04017.37
5.6.40.0050.02917.55
5.6.30.0110.04017.51
5.6.20.0090.04217.50
5.6.10.0120.04017.53
5.6.00.0060.04117.38
5.5.380.0080.02317.48
5.5.370.0030.03517.53
5.5.360.0030.04817.52
5.5.350.0100.03317.48
5.5.340.0070.04417.72
5.5.330.0050.04017.80
5.5.320.0090.04117.74
5.5.310.0050.04817.69
5.5.300.0060.02817.63
5.5.290.0070.04617.83
5.5.280.0020.04617.81
5.5.270.0050.04817.59
5.5.260.0000.04817.74
5.5.250.0030.04517.71
5.5.240.0030.04417.51
5.5.230.0090.03117.22
5.5.220.0100.04017.30
5.5.210.0130.03817.48
5.5.200.0030.04017.29
5.5.190.0030.02617.57
5.5.180.0150.03617.43
5.5.170.0090.00614.67
5.5.160.0050.04317.41
5.5.150.0050.04317.38
5.5.140.0030.03817.31
5.5.130.0050.04417.44
5.5.120.0070.04217.29
5.5.110.0070.03717.40
5.5.100.0050.04317.20
5.5.90.0100.04017.27
5.5.80.0050.04517.45
5.5.70.0080.04217.08
5.5.60.0030.04717.27
5.5.50.0070.03017.41
5.5.40.0070.04017.33
5.5.30.0100.04017.21
5.5.20.0080.04017.29
5.5.10.0090.03517.30
5.5.00.0060.02517.39
5.4.450.0050.04015.77
5.4.440.0080.04415.80
5.4.430.0070.03815.78
5.4.420.0070.04415.88
5.4.410.0050.04215.81
5.4.400.0060.03815.63
5.4.390.0100.03515.75
5.4.380.0120.03715.67
5.4.370.0020.03215.65
5.4.360.0050.04115.63
5.4.350.0060.04015.63
5.4.340.0030.04315.63
5.4.330.0080.00612.26
5.4.320.0050.04015.71
5.4.310.0050.02815.63
5.4.300.0050.04215.62
5.4.290.0070.03515.64
5.4.280.0060.03615.79
5.4.270.0090.03915.79
5.4.260.0000.04815.74
5.4.250.0030.04215.74
5.4.240.0070.03915.62
5.4.230.0050.04015.63
5.4.220.0070.03815.80
5.4.210.0100.03815.71
5.4.200.0090.04015.70
5.4.190.0040.04415.63
5.4.180.0060.02315.78
5.4.170.0050.04215.74
5.4.160.0030.02815.74
5.4.150.0030.03715.74
5.4.140.0050.04014.40
5.4.130.0030.03814.41
5.4.120.0090.04014.40
5.4.110.0070.03214.36
5.4.100.0040.02114.34
5.4.90.0080.03714.36
5.4.80.0030.04314.44
5.4.70.0120.03214.36
5.4.60.0050.03814.38
5.4.50.0050.03414.36
5.4.40.0030.04014.38
5.4.30.0110.03314.36
5.4.20.0050.04014.35
5.4.10.0070.02514.32
5.4.00.0070.03914.13
5.3.290.0090.03613.47
5.3.280.0070.04113.43
5.3.270.0030.04013.46
5.3.260.0030.03513.43
5.3.250.0020.04313.48
5.3.240.0030.04213.42
5.3.230.0040.03513.47
5.3.220.0050.04113.53
5.3.210.0060.03913.34
5.3.200.0070.04013.34
5.3.190.0050.03713.45
5.3.180.0040.03613.42
5.3.170.0030.04213.42
5.3.160.0020.02613.45
5.3.150.0050.04013.41
5.3.140.0030.04413.40
5.3.130.0050.04913.42
5.3.120.0050.04213.41
5.3.110.0030.03313.41
5.3.100.0080.03713.13
5.3.90.0040.03813.21
5.3.80.0070.02613.14
5.3.70.0050.03913.14
5.3.60.0100.03313.25
5.3.50.0020.03913.12
5.3.40.0060.02813.14
5.3.30.0040.04013.13
5.3.20.0030.03812.97
5.3.10.0070.03513.07
5.3.00.0080.03313.01

preferences:
44.9 ms | 401 KiB | 5 Q