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; } if (false !== $this->xml->$offset->asXML() && !$isAttribute) { $xml = $this->xml->$offset; } else { $xml = $this->xml[$offset]; } return $xml; } 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.70.0090.00618.81
8.3.60.0070.01416.98
8.3.50.0130.00722.17
8.3.40.0080.00819.00
8.3.30.0140.00719.46
8.3.20.0000.00820.64
8.3.10.0040.00423.91
8.3.00.0000.00919.59
8.2.180.0040.01218.51
8.2.170.0130.00322.96
8.2.160.0110.00720.52
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0030.00626.16
8.2.120.0030.00521.16
8.2.110.0090.00022.50
8.2.100.0060.00618.09
8.2.90.0000.00819.33
8.2.80.0050.00318.18
8.2.70.0030.00518.00
8.2.60.0000.00918.29
8.2.50.0040.00418.07
8.2.40.0080.00018.31
8.2.30.0070.00318.51
8.2.20.0000.00718.05
8.2.10.0030.00518.38
8.2.00.0050.00318.01
8.1.280.0070.00725.92
8.1.270.0050.00322.32
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00324.09
8.1.230.0040.00819.38
8.1.220.0000.00818.04
8.1.210.0000.00918.77
8.1.200.0030.00617.73
8.1.190.0080.00017.66
8.1.180.0030.00518.10
8.1.170.0050.00318.88
8.1.160.0000.00822.26
8.1.150.0060.00318.96
8.1.140.0000.00917.66
8.1.130.0030.00318.02
8.1.120.0080.00017.78
8.1.110.0030.00617.68
8.1.100.0070.00017.80
8.1.90.0030.00517.76
8.1.80.0040.00417.76
8.1.70.0000.00717.60
8.1.60.0040.00417.95
8.1.50.0040.00417.70
8.1.40.0000.00817.70
8.1.30.0050.00317.93
8.1.20.0080.00018.00
8.1.10.0080.00017.78
8.1.00.0030.00517.85
8.0.300.0070.00018.77
8.0.290.0050.00217.43
8.0.280.0080.00018.65
8.0.270.0030.00317.51
8.0.260.0000.00717.11
8.0.250.0030.00317.38
8.0.240.0040.00417.18
8.0.230.0040.00417.33
8.0.220.0040.00317.27
8.0.210.0070.00017.29
8.0.200.0030.00317.38
8.0.190.0000.00717.34
8.0.180.0040.00417.24
8.0.170.0030.00517.21
8.0.160.0000.00717.21
8.0.150.0080.00017.12
8.0.140.0030.00517.08
8.0.130.0110.00013.66
8.0.120.0040.00417.27
8.0.110.0040.00417.07
8.0.100.0000.00717.00
8.0.90.0040.00417.31
8.0.80.0030.01217.25
8.0.70.0000.00717.29
8.0.60.0020.00517.09
8.0.50.0040.00417.16
8.0.30.0100.01117.17
8.0.20.0070.01117.40
8.0.10.0040.00417.21
8.0.00.0150.00817.21
7.4.330.0050.00015.38
7.4.320.0030.00317.00
7.4.300.0070.00016.83
7.4.290.0060.00316.90
7.4.280.0040.00416.79
7.4.270.0030.00316.71
7.4.260.0070.00016.88
7.4.250.0060.00316.87
7.4.240.0020.00516.89
7.4.230.0000.00716.68
7.4.220.0120.00616.95
7.4.210.0070.00816.84
7.4.200.0000.00716.86
7.4.190.0000.00816.84
7.4.160.0100.00716.75
7.4.150.0110.00717.40
7.4.140.0060.01117.86
7.4.130.0100.00716.83
7.4.120.0100.00916.86
7.4.110.0130.00316.84
7.4.100.0170.00916.90
7.4.90.0110.00616.62
7.4.80.0150.00619.39
7.4.70.0030.01316.81
7.4.60.0090.01216.64
7.4.50.0040.00416.80
7.4.40.0030.01322.77
7.4.30.0060.01016.89
7.4.00.0110.00415.03
7.3.330.0070.00013.45
7.3.320.0000.00513.64
7.3.310.0080.00016.70
7.3.300.0070.00016.60
7.3.290.0070.00716.66
7.3.280.0090.01116.62
7.3.270.0120.00617.40
7.3.260.0090.00916.63
7.3.250.0100.00716.76
7.3.240.0110.01316.65
7.3.230.0070.01016.93
7.3.210.0100.01316.57
7.3.200.0090.00919.39
7.3.190.0170.00616.78
7.3.180.0060.00916.68
7.3.170.0060.00916.96
7.3.160.0120.00316.61
7.3.120.0070.00715.11
7.2.330.0090.00916.93
7.2.320.0120.00616.73
7.2.310.0140.00316.98
7.2.300.0150.00316.75
7.2.290.0000.01717.09
7.2.120.0090.00616.74
7.2.110.0000.01116.84
7.2.100.0000.01516.79
7.2.90.0090.00616.80
7.2.80.0060.00616.81
7.2.70.0090.00616.91
7.2.60.0070.00717.06
7.2.50.0040.00717.22
7.2.40.0070.00717.21
7.2.30.0070.00316.96
7.2.20.0000.00917.14
7.2.10.0000.01117.05
7.2.00.0080.00618.18
7.1.240.0130.00315.82
7.1.230.0030.01016.14
7.1.220.0070.00415.83
7.1.210.0090.00615.96
7.1.200.0060.00915.92
7.1.190.0070.00715.98
7.1.180.0060.00816.14
7.1.170.0000.01315.85
7.1.160.0080.00415.80
7.1.150.0070.00715.99
7.1.140.0090.00315.84
7.1.130.0110.00015.82
7.1.120.0000.01415.78
7.1.110.0070.00315.93
7.1.100.0040.01117.10
7.1.90.0000.01216.05
7.1.80.0000.01415.97
7.1.70.0050.00616.44
7.1.60.0090.00917.60
7.1.50.0040.00916.58
7.1.40.0000.01215.93
7.1.30.0070.00415.97
7.1.20.0070.00715.90
7.1.10.0050.00515.89
7.1.00.0060.04019.05
7.0.320.0000.00815.67
7.0.310.0030.00615.30
7.0.300.0030.00615.45
7.0.290.0030.00615.54
7.0.280.0030.01015.41
7.0.270.0100.00315.46
7.0.260.0060.00915.65
7.0.250.0070.00715.50
7.0.240.0000.01215.67
7.0.230.0040.01115.32
7.0.220.0040.00815.68
7.0.210.0050.00515.55
7.0.200.0030.01016.33
7.0.190.0000.01315.59
7.0.180.0060.00615.47
7.0.170.0000.01015.73
7.0.160.0080.00315.60
7.0.150.0070.00015.76
7.0.140.0070.03818.92
7.0.130.0060.00615.60
7.0.120.0060.00615.74
7.0.110.0140.02017.69
7.0.100.0120.02217.82
7.0.90.0120.02417.87
7.0.80.0070.01817.80
7.0.70.0000.02317.89
7.0.60.0120.01517.87
7.0.50.0220.04017.87
7.0.40.0020.02316.68
7.0.30.0070.01816.86
7.0.20.0080.02016.73
7.0.10.0070.01816.69
7.0.00.0060.02316.73
5.6.380.0070.00714.38
5.6.370.0040.00414.72
5.6.360.0070.00714.95
5.6.350.0070.00714.67
5.6.340.0100.00314.65
5.6.330.0070.00714.52
5.6.320.0060.00614.31
5.6.310.0030.00714.71
5.6.300.0080.00414.64
5.6.290.0030.01014.52
5.6.280.0080.03717.84
5.6.270.0060.00714.73
5.6.260.0000.02517.77
5.6.250.0050.02317.64
5.6.240.0080.01717.89
5.6.230.0050.02117.62
5.6.220.0040.02117.51
5.6.210.0070.02017.69
5.6.200.0110.01417.75
5.6.190.0050.02217.64
5.6.180.0050.02517.70
5.6.170.0070.02017.71
5.6.160.0080.02017.78
5.6.150.0000.02617.67
5.6.140.0050.03817.48
5.6.130.0030.02417.61
5.6.120.0030.02217.63
5.6.110.0070.02417.74
5.6.100.0050.04017.53
5.6.90.0070.02117.59
5.6.80.0020.02817.26
5.6.70.0050.02217.33
5.6.60.0080.02017.32
5.6.50.0050.03317.24
5.6.40.0060.03317.20
5.6.30.0060.02217.36
5.6.20.0030.04417.31
5.6.10.0030.03017.38
5.6.00.0110.02517.21
5.5.380.0080.01714.60
5.5.370.0020.02014.67
5.5.360.0000.02214.53
5.5.350.0010.02614.50
5.5.340.0080.02014.97
5.5.330.0030.02814.77
5.5.320.0060.02614.79
5.5.310.0020.02614.84
5.5.300.0020.02714.94
5.5.290.0060.02714.77
5.5.280.0020.02414.65
5.5.270.0100.04014.82
5.5.260.0070.01714.86
5.5.250.0030.02314.52
5.5.240.0050.01814.33
5.5.230.0020.04014.46
5.5.220.0080.01814.43
5.5.210.0020.02214.36
5.5.200.0080.04114.40
5.5.190.0060.02014.34
5.5.180.0000.02814.45
5.5.170.0060.00314.52
5.5.160.0070.04014.37
5.5.150.0000.02614.48
5.5.140.0030.02014.35
5.5.130.0010.02614.45
5.5.120.0030.03814.35
5.5.110.0040.02814.54
5.5.100.0000.02714.24
5.5.90.0030.02314.53
5.5.80.0060.02514.42
5.5.70.0170.01314.35
5.5.60.0030.02314.41
5.5.50.0030.03314.34
5.5.40.0070.03414.38
5.5.30.0080.02214.50
5.5.20.0050.02214.35
5.5.10.0070.02014.22
5.5.00.0040.02214.41
5.4.450.0040.02315.54
5.4.440.0010.03415.43
5.4.430.0050.02515.34
5.4.420.0020.02115.29
5.4.410.0060.02115.33
5.4.400.0070.01915.31
5.4.390.0030.02115.35
5.4.380.0070.02215.25
5.4.370.0000.03015.13
5.4.360.0020.03015.22
5.4.350.0100.01715.24
5.4.340.0120.03215.33
5.4.330.0030.00811.51
5.4.320.0030.02115.14
5.4.310.0020.02415.23
5.4.300.0020.03615.20
5.4.290.0040.02315.21
5.4.280.0020.02515.17
5.4.270.0020.02215.34
5.4.260.0060.04215.12
5.4.250.0020.02315.39
5.4.240.0060.03215.25
5.4.230.0020.02315.35
5.4.220.0050.03315.27
5.4.210.0120.02715.22
5.4.200.0070.03915.11
5.4.190.0110.01515.30
5.4.180.0050.03315.19
5.4.170.0070.02215.24
5.4.160.0070.02115.24
5.4.150.0090.01915.33
5.4.140.0090.02013.94
5.4.130.0100.02113.94
5.4.120.0070.03513.92
5.4.110.0120.02613.96
5.4.100.0100.03813.84
5.4.90.0090.03214.08
5.4.80.0100.03013.99
5.4.70.0090.03514.05
5.4.60.0090.03613.95
5.4.50.0060.01914.00
5.4.40.0070.02013.94
5.4.30.0060.02214.03
5.4.20.0080.02013.88
5.4.10.0060.02514.06
5.4.00.0050.02013.74
5.3.290.0030.02112.78
5.3.280.0100.03012.78
5.3.270.0070.03912.83
5.3.260.0050.02012.74
5.3.250.0050.02012.78
5.3.240.0080.02312.64
5.3.230.0060.02012.77
5.3.220.0040.04412.67
5.3.210.0020.04112.65
5.3.200.0050.02912.67
5.3.190.0120.03712.69
5.3.180.0090.02812.80
5.3.170.0030.02312.74
5.3.160.0110.02712.73
5.3.150.0070.03712.65
5.3.140.0040.03312.70
5.3.130.0090.02312.70
5.3.120.0070.02112.65
5.3.110.0070.02312.69
5.3.100.0080.01812.48
5.3.90.0050.02012.54
5.3.80.0050.02012.40
5.3.70.0060.02112.31
5.3.60.0060.02012.37
5.3.50.0060.02012.47
5.3.40.0050.02212.36
5.3.30.0100.01412.45
5.3.20.0030.01812.31
5.3.10.0070.01712.11
5.3.00.0030.02012.11
5.2.170.0080.01511.11
5.2.160.0030.01611.11
5.2.150.0060.01711.11
5.2.140.0070.02211.11
5.2.130.0050.01911.11
5.2.120.0050.01511.11
5.2.110.0040.03111.11
5.2.100.0020.01911.11
5.2.90.0070.01311.11
5.2.80.0020.02611.11
5.2.70.0010.02811.11
5.2.60.0050.01611.11
5.2.50.0030.02311.11
5.2.40.0050.01611.11
5.2.30.0040.01611.11
5.2.20.0050.02311.11
5.2.10.0050.01711.11
5.2.00.0030.01611.11
5.1.60.0050.01511.11
5.1.50.0020.02411.11
5.1.40.0020.02511.11
5.1.30.0040.01511.11
5.1.20.0050.01311.11
5.1.10.0060.01311.11
5.1.00.0050.02711.11
5.0.50.0020.01511.11
5.0.40.0070.01711.11
5.0.30.0030.01811.11
5.0.20.0060.01611.11
5.0.10.0020.01811.11
5.0.00.0030.03011.11
4.4.90.0020.01111.11
4.4.80.0000.01211.11
4.4.70.0020.00911.11
4.4.60.0020.01411.11
4.4.50.0030.01011.11
4.4.40.0060.02411.11
4.4.30.0000.01411.11
4.4.20.0010.00811.11
4.4.10.0040.01411.11
4.4.00.0030.02211.11
4.3.110.0020.01611.11
4.3.100.0020.01811.11
4.3.90.0020.01011.11
4.3.80.0020.02111.11
4.3.70.0020.01711.11
4.3.60.0050.00511.11
4.3.50.0030.01711.11
4.3.40.0030.01611.11
4.3.30.0000.01411.11
4.3.20.0030.01811.11
4.3.10.0010.01011.11
4.3.00.0000.01211.11

preferences:
51.02 ms | 401 KiB | 5 Q