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 .= $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.0070.01518.68
8.3.50.0100.01422.18
8.3.40.0040.01118.92
8.3.30.0110.00319.04
8.3.20.0080.00018.95
8.3.10.0030.00621.05
8.3.00.0080.00021.99
8.2.180.0070.01116.75
8.2.170.0110.00722.96
8.2.160.0030.01220.60
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0000.00826.16
8.2.120.0000.00821.00
8.2.110.0060.00620.64
8.2.100.0110.00018.03
8.2.90.0000.00819.32
8.2.80.0090.00017.97
8.2.70.0000.00818.00
8.2.60.0080.00018.05
8.2.50.0030.00618.13
8.2.40.0090.00018.41
8.2.30.0040.00421.21
8.2.20.0040.00417.98
8.2.10.0040.00418.00
8.2.00.0050.00317.87
8.1.280.0110.00725.92
8.1.270.0040.00423.99
8.1.260.0110.00426.35
8.1.250.0000.00828.09
8.1.240.0120.00922.11
8.1.230.0060.00622.23
8.1.220.0030.00518.77
8.1.210.0030.00519.00
8.1.200.0090.00017.49
8.1.190.0030.00517.79
8.1.180.0080.00018.10
8.1.170.0000.01018.75
8.1.160.0040.00419.04
8.1.150.0080.00018.93
8.1.140.0040.00417.66
8.1.130.0000.00717.93
8.1.120.0040.00417.73
8.1.110.0030.00617.69
8.1.100.0040.00417.58
8.1.90.0000.00717.68
8.1.80.0080.00017.54
8.1.70.0030.00317.53
8.1.60.0030.00617.80
8.1.50.0080.00017.61
8.1.40.0050.00317.78
8.1.30.0040.00417.77
8.1.20.0000.00817.82
8.1.10.0030.00517.69
8.1.00.0040.00717.75
8.0.300.0040.00420.15
8.0.290.0000.00717.30
8.0.280.0040.00418.54
8.0.270.0050.00217.23
8.0.260.0000.00717.10
8.0.250.0000.00717.21
8.0.240.0060.00317.21
8.0.230.0040.00417.30
8.0.220.0030.00417.09
8.0.210.0040.00417.05
8.0.200.0030.00317.25
8.0.190.0000.00717.23
8.0.180.0040.00417.16
8.0.170.0000.00917.07
8.0.160.0040.00417.14
8.0.150.0040.00417.05
8.0.140.0000.00817.01
8.0.130.0060.00013.67
8.0.120.0050.00217.18
8.0.110.0040.00417.13
8.0.100.0030.00517.00
8.0.90.0040.00417.07
8.0.80.0110.01117.17
8.0.70.0030.00517.05
8.0.60.0070.00017.07
8.0.50.0050.00317.22
8.0.30.0090.01317.49
8.0.20.0100.01017.40
8.0.10.0040.00417.16
8.0.00.0060.01117.01
7.4.330.0000.00516.80
7.4.320.0000.00716.78
7.4.300.0030.00316.81
7.4.290.0030.00516.70
7.4.280.0070.00016.91
7.4.270.0000.00716.89
7.4.260.0030.00313.52
7.4.250.0040.00416.87
7.4.240.0070.00016.79
7.4.230.0040.00316.79
7.4.220.0150.00316.71
7.4.210.0080.00916.88
7.4.200.0000.00716.60
7.4.190.0040.00416.89
7.4.160.0100.01416.92
7.4.150.0130.01017.40
7.4.140.0070.01117.86
7.4.130.0110.00916.93
7.4.120.0100.00716.90
7.4.110.0090.00816.83
7.4.100.0120.00616.71
7.4.90.0140.00316.73
7.4.80.0120.01219.39
7.4.70.0100.00916.78
7.4.60.0090.00816.71
7.4.50.0030.00616.65
7.4.40.0000.01722.77
7.4.30.0100.00716.73
7.4.00.0100.00715.31
7.3.330.0000.00513.65
7.3.320.0050.00013.50
7.3.310.0000.00816.70
7.3.300.0070.00016.61
7.3.290.0090.01216.68
7.3.280.0120.00616.61
7.3.270.0080.01017.40
7.3.260.0120.00818.24
7.3.250.0130.00516.63
7.3.240.0060.01216.67
7.3.230.0090.00916.79
7.3.210.0040.01516.88
7.3.200.0070.01319.39
7.3.190.0100.01316.94
7.3.180.0100.00716.82
7.3.170.0060.01816.79
7.3.160.0030.01416.68
7.3.120.0070.01015.13
7.3.10.0050.00916.85
7.3.00.0050.01216.87
7.2.330.0060.01416.88
7.2.320.0000.01716.97
7.2.310.0180.00416.89
7.2.300.0090.00916.82
7.2.290.0110.00617.06
7.2.130.0110.00717.16
7.2.120.0060.01117.13
7.2.110.0020.01517.16
7.2.100.0120.00317.08
7.2.90.0060.00817.18
7.2.80.0080.00717.06
7.2.70.0090.00717.04
7.2.60.0050.01017.11
7.2.50.0070.00917.04
7.2.40.0080.00417.22
7.2.30.0100.00517.21
7.2.20.0060.01217.06
7.2.10.0080.00917.24
7.2.00.0040.00917.96
7.1.250.0050.01115.96
7.1.100.0030.01018.53
7.1.70.0030.00617.44
7.1.60.0040.01819.08
7.1.50.0060.01635.07
7.1.00.0000.05022.37
7.0.200.0000.00817.11
7.0.140.0100.06322.18
7.0.100.0070.08019.99
7.0.90.0070.09020.03
7.0.80.0100.05020.18
7.0.70.0230.08719.96
7.0.60.0100.08320.02
7.0.50.0100.08720.43
7.0.40.0100.08320.09
7.0.30.0100.08320.08
7.0.20.0030.05020.07
7.0.10.0070.06720.07
7.0.00.0030.07720.09
5.6.280.0070.07021.11
5.6.250.0200.07020.83
5.6.240.0100.05320.81
5.6.230.0070.07320.55
5.6.220.0030.05720.60
5.6.210.0170.06020.79
5.6.200.0100.08021.10
5.6.190.0100.07721.07
5.6.180.0100.05021.11
5.6.170.0070.05021.09
5.6.160.0100.07721.00
5.6.150.0070.05321.16
5.6.140.0070.06021.18
5.6.130.0070.06721.09
5.6.120.0070.06321.09
5.6.110.0030.07321.14
5.6.100.0030.09321.06
5.6.90.0070.07721.07
5.6.80.0070.07320.47
5.6.70.0170.07020.39
5.6.60.0200.06020.49
5.6.50.0070.05720.37
5.6.40.0200.06720.49
5.6.30.0100.07320.36
5.6.20.0030.04320.50
5.6.10.0070.07020.49
5.6.00.0030.08720.40
5.5.380.0100.07720.45
5.5.370.0030.08320.56
5.5.360.0100.08020.39
5.5.350.0100.06320.42
5.5.340.0100.08020.87
5.5.330.0100.07720.80
5.5.320.0070.08720.94
5.5.310.0200.07020.93
5.5.300.0030.08320.78
5.5.290.0100.07020.92
5.5.280.0100.07720.91
5.5.270.0170.07020.96
5.5.260.0030.08720.77
5.5.250.0030.08720.59
5.5.240.0100.07320.21
5.5.230.0100.08020.29
5.5.220.0030.08020.29
5.5.210.0030.05020.20
5.5.200.0170.07020.18
5.5.190.0070.08020.31
5.5.180.0100.06720.20
5.5.160.0170.07720.25
5.5.150.0100.08020.30
5.5.140.0070.08320.20
5.5.130.0100.07720.28
5.5.120.0130.04720.13
5.5.110.0070.08320.25
5.5.100.0070.08020.13
5.5.90.0100.07320.21
5.5.80.0070.08020.20
5.5.70.0070.07720.13
5.5.60.0130.07020.21
5.5.50.0070.04020.10
5.5.40.0130.07320.14
5.5.30.0170.06320.18
5.5.20.0100.07020.09
5.5.10.0070.07720.13
5.5.00.0130.06720.18
5.4.450.0100.06019.36
5.4.440.0130.07019.46
5.4.430.0130.07319.22
5.4.420.0100.06019.22
5.4.410.0130.03019.41
5.4.400.0070.04318.86
5.4.390.0000.05019.12
5.4.380.0070.06319.23
5.4.370.0030.08019.13
5.4.360.0130.07019.04
5.4.350.0100.07019.20
5.4.340.0030.04719.09
5.4.320.0130.05319.12
5.4.310.0130.07019.14
5.4.300.0100.07019.13
5.4.290.0230.05719.18
5.4.280.0030.05319.18
5.4.270.0030.08319.12
5.4.260.0100.07018.94
5.4.250.0100.07319.14
5.4.240.0070.07719.08
5.4.230.0000.06719.13
5.4.220.0230.06319.03
5.4.210.0070.06319.18
5.4.200.0100.07719.20
5.4.190.0100.06318.86
5.4.180.0200.06019.02
5.4.170.0070.05019.03
5.4.160.0100.07719.11
5.4.150.0100.08019.11
5.4.140.0100.06316.39
5.4.130.0130.05716.32
5.4.120.0100.07316.24
5.4.110.0130.06716.45
5.4.100.0100.06016.52
5.4.90.0130.06716.56
5.4.80.0070.07716.43
5.4.70.0030.06716.37
5.4.60.0070.07016.49
5.4.50.0000.07016.45
5.4.40.0100.06716.38
5.4.30.0170.06716.49
5.4.20.0030.08016.30
5.4.10.0170.06316.42
5.4.00.0070.07015.77
5.3.290.0130.07714.59
5.3.280.0030.08314.60
5.3.270.0030.06014.66
5.3.260.0100.07314.59
5.3.250.0000.08014.72
5.3.240.0100.07014.54
5.3.230.0130.07314.55
5.3.220.0170.06014.57
5.3.210.0130.07014.71
5.3.200.0070.07714.56
5.3.190.0030.08014.49
5.3.180.0000.08014.51
5.3.170.0170.06714.52
5.3.160.0130.07314.58
5.3.150.0000.07714.68
5.3.140.0030.08014.56
5.3.130.0030.08014.51
5.3.120.0130.07014.56
5.3.110.0100.06714.55
5.3.100.0130.07014.02
5.3.90.0070.07014.14
5.3.80.0100.06313.90
5.3.70.0130.07713.94
5.3.60.0070.07314.14
5.3.50.0170.06014.06
5.3.40.0130.07013.96
5.3.30.0070.07713.97
5.3.20.0000.07713.75
5.3.10.0130.03713.68
5.3.00.0070.03313.77

preferences:
44.75 ms | 401 KiB | 5 Q