3v4l.org

run code in 300+ PHP versions simultaneously
<?php class XmlArrayAccessIterator implements ArrayAccess, IteratorAggregate { const ATTRIBUTE_PREFIX = '@'; private $xml; public function __construct(SimpleXmlIterator $xml) { $this->xml = $xml; } private function getElement($offset) { $isAttribute = false; if (substr($offset, 0, 1) == self::ATTRIBUTE_PREFIX) { $offset = substr($offset, 1); $isAttribute = false; } var_dump($this->xml->$offset->asXML()); if (false !== $this->xml->$offset->asXML() && !$isAttribute) { $xml = $this->xml->$offset; } else { $xml = $this->xml[$offset]; } } public function offsetExists($offset) { return !is_null($this->getElement($offset)); } public function offsetGet($offset) { if ($this->xml->getName() == $offset) { return $this; } $xml = $this->getElement($offset); if (is_null($xml)) { throw new RuntimeException('unknown node or attribute "' . $offset . '"'); } return new self($xml); } public function offsetSet($offset, $value) { throw new RuntimeException('This is readonly. writing to "' . (string) $offset . '" with value "' . (string) $value . '" not possible'); } public function offsetUnset($offset) { throw new RuntimeException('This is readonly. Unsetting "' . (string) $offset . '" not possible'); } public function getIterator() { return $this->xml; } public function __toString() { return (string) $this->xml; } } $xml = '<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading foo="bar">Reminder</heading> <body>Don\'t forget me this weekend!</body> <recursive> <val>2</val> <val>4</val> </recursive> </note>'; $simple = new SimpleXmlIterator($xml); $xml = new XmlArrayAccessIterator($simple); echo $xml['note']['to']; echo $xml['note']['recursive']['val'][1]; echo $xml['note']['heading']['@foo'];

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.0060.00917.25
8.3.50.0130.00816.88
8.3.40.0000.01619.22
8.3.30.0110.00719.20
8.3.20.0040.00419.18
8.3.10.0030.00520.93
8.3.00.0050.00319.63
8.2.180.0180.00316.88
8.2.170.0040.01122.96
8.2.160.0170.00321.36
8.2.150.0090.00024.18
8.2.140.0080.00024.66
8.2.130.0110.00726.16
8.2.120.0080.00019.73
8.2.110.0160.00621.26
8.2.100.0030.01018.22
8.2.90.0040.00721.18
8.2.80.0000.00818.16
8.2.70.0060.00318.00
8.2.60.0030.00518.15
8.2.50.0060.00318.07
8.2.40.0040.00418.34
8.2.30.0000.00918.42
8.2.20.0040.00418.04
8.2.10.0070.00318.07
8.2.00.0100.00018.02
8.1.280.0140.00425.92
8.1.270.0080.00024.66
8.1.260.0060.00326.35
8.1.250.0000.00828.09
8.1.240.0030.00621.11
8.1.230.0110.00021.29
8.1.220.0050.00318.02
8.1.210.0040.00419.16
8.1.200.0060.00317.72
8.1.190.0080.00017.77
8.1.180.0040.00418.10
8.1.170.0080.00019.08
8.1.160.0040.00419.04
8.1.150.0000.00818.95
8.1.140.0030.00617.79
8.1.130.0000.00718.10
8.1.120.0040.00417.59
8.1.110.0030.00517.74
8.1.100.0050.00317.80
8.1.90.0000.00817.80
8.1.80.0000.00717.77
8.1.70.0030.00317.64
8.1.60.0040.00817.74
8.1.50.0030.00617.77
8.1.40.0090.00017.72
8.1.30.0040.00417.90
8.1.20.0030.00517.91
8.1.10.0030.00517.80
8.1.00.0040.00417.81
8.0.300.0040.00420.23
8.0.290.0000.00717.13
8.0.280.0040.00418.74
8.0.270.0000.00717.59
8.0.260.0030.00317.20
8.0.250.0000.00817.20
8.0.240.0070.00017.32
8.0.230.0070.00017.28
8.0.220.0030.00317.26
8.0.210.0040.00417.14
8.0.200.0030.00317.40
8.0.190.0000.00717.34
8.0.180.0000.00717.09
8.0.170.0030.00617.36
8.0.160.0000.00717.26
8.0.150.0040.00417.24
8.0.140.0060.00617.15
8.0.130.0030.00313.72
8.0.120.0000.00717.16
8.0.110.0040.00417.14
8.0.100.0040.00417.11
8.0.90.0020.00517.30
8.0.80.0060.01017.23
8.0.70.0040.00417.04
8.0.60.0050.00317.18
8.0.50.0040.00417.34
8.0.30.0090.01217.34
8.0.20.0140.01117.51
8.0.10.0090.00017.22
8.0.00.0080.01017.47
7.4.330.0030.00313.21
7.4.320.0070.00016.84
7.4.300.0030.00316.66
7.4.290.0030.00516.92
7.4.280.0060.00316.81
7.4.270.0000.00916.77
7.4.260.0030.00313.70
7.4.250.0060.00316.78
7.4.240.0000.00716.85
7.4.230.0040.00416.89
7.4.220.0090.00916.89
7.4.210.0100.00616.91
7.4.200.0000.00716.96
7.4.190.0040.00416.89
7.4.160.0060.01116.81
7.4.150.0120.00816.81
7.4.140.0100.00816.93
7.4.130.0120.00716.75
7.4.120.0140.00516.96
7.4.110.0070.01016.90
7.4.100.0150.00416.82
7.4.90.0160.00616.87
7.4.80.0090.00819.39
7.4.70.0090.00916.94
7.4.60.0090.01116.79
7.4.50.0060.00316.59
7.4.40.0130.00316.89
7.4.30.0130.00316.95
7.4.00.0060.01115.21
7.3.330.0060.00013.55
7.3.320.0030.00313.72
7.3.310.0040.00416.78
7.3.300.0030.00316.61
7.3.290.0040.01116.75
7.3.280.0080.01016.72
7.3.270.0050.01416.63
7.3.260.0090.00916.71
7.3.250.0080.00916.81
7.3.240.0120.00616.96
7.3.230.0140.00316.76
7.3.210.0030.01516.91
7.3.200.0150.00316.77
7.3.190.0030.01316.74
7.3.180.0120.00416.75
7.3.170.0060.01416.71
7.3.160.0000.01616.75
7.3.120.0080.00714.97
7.3.110.0030.01015.09
7.3.100.0090.00615.21
7.3.90.0060.00315.14
7.3.80.0060.00614.94
7.3.70.0060.00915.25
7.3.60.0090.00414.95
7.3.50.0100.00015.23
7.3.40.0040.00715.06
7.3.30.0070.00714.80
7.3.20.0090.00316.85
7.3.10.0000.01216.68
7.3.00.0030.00716.93
7.2.330.0040.01317.11
7.2.320.0060.01317.02
7.2.310.0060.01316.86
7.2.300.0160.00017.11
7.2.290.0080.00816.82
7.2.250.0030.01715.23
7.2.240.0070.01415.13
7.2.230.0120.00314.81
7.2.220.0060.00315.39
7.2.210.0060.00915.34
7.2.200.0030.01015.38
7.2.190.0060.00915.38
7.2.180.0000.01515.39
7.2.170.0060.00614.95
7.2.60.0000.01416.96
7.2.00.0040.00819.87
7.1.330.0040.01215.96
7.1.320.0100.00316.00
7.1.310.0090.00615.86
7.1.300.0030.01016.16
7.1.290.0030.00916.10
7.1.280.0060.00315.83
7.1.270.0040.01115.87
7.1.260.0070.00316.17
7.1.200.0000.01116.00
7.1.100.0000.01417.91
7.1.70.0000.01117.15
7.1.60.0200.00319.40
7.1.50.0130.01017.08
7.1.00.0030.06322.57
7.0.200.0030.00616.83
7.0.140.0030.07322.05
7.0.120.0000.07022.24
7.0.60.0030.08020.05
7.0.50.0000.07017.95
7.0.40.0070.04717.93
7.0.30.0070.08718.00
7.0.20.0070.05717.86
7.0.10.0070.06717.86
7.0.00.0200.05717.86
5.6.280.0070.07021.04
5.6.210.0030.04020.53
5.6.200.0070.04018.24
5.6.190.0070.05318.32
5.6.180.0130.05018.28
5.6.170.0030.08318.32
5.6.160.0100.06318.41
5.6.150.0070.04018.37
5.6.140.0130.04018.19
5.6.130.0030.04718.38
5.6.120.0100.04018.30
5.6.110.0170.07018.34
5.6.100.0170.07018.35
5.6.90.0030.06318.26
5.6.80.0130.05717.77
5.6.70.0130.07017.76
5.6.60.0100.07317.56
5.6.50.0100.07717.79
5.6.40.0130.07317.77
5.6.30.0030.07317.60
5.6.20.0070.06717.74
5.6.10.0130.07717.62
5.6.00.0100.07317.63
5.5.350.0330.07320.56
5.5.340.0070.03718.09
5.5.330.0170.07018.16
5.5.320.0170.04018.15
5.5.310.0070.08018.06
5.5.300.0030.06318.04
5.5.290.0030.05718.02
5.5.280.0070.08718.16
5.5.270.0130.05018.10
5.5.260.0030.05718.12
5.5.250.0070.05717.96
5.5.240.0130.07017.54
5.5.230.0070.07317.44
5.5.220.0200.05017.59
5.5.210.0030.07717.40
5.5.200.0100.07717.63
5.5.190.0000.08317.37
5.5.180.0030.08317.48
5.5.160.0100.07017.38
5.5.150.0130.07017.50
5.5.140.0170.07017.53
5.5.130.0130.07017.46
5.5.120.0070.08017.37
5.5.110.0070.04717.55
5.5.100.0000.06017.44
5.5.90.0100.05717.38
5.5.80.0100.07317.47
5.5.70.0030.05017.37
5.5.60.0030.05017.35
5.5.50.0070.07717.27
5.5.40.0130.06317.30
5.5.30.0100.06017.29
5.5.20.0070.05017.23
5.5.10.0130.07017.44
5.5.00.0130.04317.39
5.4.450.0100.05719.39
5.4.440.0100.07019.54
5.4.430.0070.07019.38
5.4.420.0070.07719.28
5.4.410.0030.07019.41
5.4.400.0170.06719.03
5.4.390.0070.07719.21
5.4.380.0100.06019.13
5.4.370.0100.05319.35
5.4.360.0030.05019.06
5.4.350.0130.07019.05
5.4.340.0100.04719.03
5.4.320.0030.08019.35
5.4.310.0030.06319.21
5.4.300.0030.04718.96
5.4.290.0070.05018.97
5.4.280.0070.06019.25
5.4.270.0100.04319.19
5.4.260.0100.06719.19
5.4.250.0070.07719.13
5.4.240.0070.08318.96
5.4.230.0030.07319.33
5.4.220.0130.03319.12
5.4.210.0070.07319.11
5.4.200.0030.08019.20
5.4.190.0070.06019.05
5.4.180.0200.06019.11
5.4.170.0030.08019.22
5.4.160.0030.04019.32
5.4.150.0030.08019.14
5.4.140.0070.03716.54
5.4.130.0070.07016.55
5.4.120.0070.06716.52
5.4.110.0030.07716.61
5.4.100.0030.07316.54
5.4.90.0070.05716.57
5.4.80.0030.03716.69
5.4.70.0100.03016.52
5.4.60.0030.07016.64
5.4.50.0030.04716.57
5.4.40.0100.06716.55
5.4.30.0070.07716.57
5.4.20.0100.07316.59
5.4.10.0130.06316.48
5.4.00.0170.06716.00
5.3.290.0100.07314.80
5.3.280.0070.07714.75
5.3.270.0170.06714.79
5.3.260.0130.05014.88
5.3.250.0070.07314.78
5.3.240.0030.06714.68
5.3.230.0000.05014.75
5.3.220.0000.05714.82
5.3.210.0030.08314.71
5.3.200.0030.05314.73
5.3.190.0130.07014.88
5.3.180.0200.03714.83
5.3.170.0030.04314.79
5.3.160.0030.04314.70
5.3.150.0070.07314.73
5.3.140.0070.07314.65
5.3.130.0100.04314.64
5.3.120.0130.07314.71
5.3.110.0100.06014.60
5.3.100.0070.05714.18
5.3.90.0070.07014.07
5.3.80.0100.04014.32
5.3.70.0070.06714.15
5.3.60.0130.06714.21
5.3.50.0100.06014.11
5.3.40.0030.05314.08
5.3.30.0030.08314.21
5.3.20.0070.06313.96
5.3.10.0030.06313.80
5.3.00.0070.07013.81
5.2.170.0030.04011.40
5.2.160.0100.05711.32
5.2.150.0070.03311.32
5.2.140.0070.06311.21
5.2.130.0070.05311.23
5.2.120.0070.06011.11
5.2.110.0070.06011.26
5.2.100.0130.05311.08
5.2.90.0100.05711.23
5.2.80.0030.04011.35
5.2.70.0100.05711.27
5.2.60.0070.02711.23
5.2.50.0030.05011.16
5.2.40.0030.05710.98
5.2.30.0070.06010.96
5.2.20.0100.05710.95
5.2.10.0000.03711.06
5.2.00.0070.02710.89
5.1.60.0030.05710.11
5.1.50.0070.05010.05
5.1.40.0070.0239.99
5.1.30.0070.06010.34
5.1.20.0000.05310.47
5.1.10.0130.04710.22
5.1.00.0070.04310.25
5.0.50.0030.0438.72
5.0.40.0030.0438.72
5.0.30.0070.0478.72
5.0.20.0030.0408.72
5.0.10.0070.0378.72
5.0.00.0030.0478.72
4.4.90.0000.0378.72
4.4.80.0000.0178.72
4.4.70.0070.0338.72
4.4.60.0000.0178.72
4.4.50.0000.0178.72
4.4.40.0030.0278.72
4.4.30.0000.0238.72
4.4.20.0070.0338.72
4.4.10.0000.0378.72
4.4.00.0000.0508.72
4.3.110.0000.0408.72
4.3.100.0000.0338.72
4.3.90.0030.0308.72
4.3.80.0070.0408.72
4.3.70.0000.0278.72
4.3.60.0000.0308.72
4.3.50.0030.0278.72
4.3.40.0030.0508.72
4.3.30.0000.0308.72
4.3.20.0000.0408.72
4.3.10.0000.0378.72
4.3.00.0000.0238.72

preferences:
43.68 ms | 401 KiB | 5 Q