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']; 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.0140.00018.80
8.3.50.0060.01122.17
8.3.40.0140.00419.22
8.3.30.0160.00319.42
8.3.20.0120.00320.35
8.3.10.0030.00523.91
8.3.00.0000.00820.86
8.2.180.0100.01017.13
8.2.170.0120.00322.96
8.2.160.0130.00622.46
8.2.150.0130.00324.18
8.2.140.0050.00524.66
8.2.130.0140.00426.16
8.2.120.0060.00319.95
8.2.110.0090.00022.48
8.2.100.0000.01218.09
8.2.90.0000.00819.50
8.2.80.0040.00418.30
8.2.70.0000.00817.88
8.2.60.0050.00318.30
8.2.50.0090.00018.07
8.2.40.0040.00418.53
8.2.30.0030.00618.43
8.2.20.0040.00418.12
8.2.10.0030.00519.77
8.2.00.0070.00018.05
8.1.280.0110.00525.92
8.1.270.0030.00524.05
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0060.00324.09
8.1.230.0080.00419.40
8.1.220.0000.00817.91
8.1.210.0000.00918.77
8.1.200.0000.00917.60
8.1.190.0000.00817.79
8.1.180.0000.00818.10
8.1.170.0040.00418.89
8.1.160.0040.00422.32
8.1.150.0090.00018.87
8.1.140.0040.00417.73
8.1.130.0030.00618.11
8.1.120.0070.00017.75
8.1.110.0000.00917.75
8.1.100.0000.01117.85
8.1.90.0000.00717.84
8.1.80.0030.00517.70
8.1.70.0040.00417.72
8.1.60.0000.00917.87
8.1.50.0000.00817.91
8.1.40.0030.00517.75
8.1.30.0050.00317.80
8.1.20.0030.00617.81
8.1.10.0030.00617.69
8.1.00.0040.00417.67
8.0.300.0040.00418.77
8.0.290.0080.00017.43
8.0.280.0030.00318.73
8.0.270.0050.00317.46
8.0.260.0040.00417.07
8.0.250.0000.00717.29
8.0.240.0040.00417.37
8.0.230.0000.00817.21
8.0.220.0030.00317.29
8.0.210.0050.00317.12
8.0.200.0000.00817.15
8.0.190.0000.00817.27
8.0.180.0050.00317.32
8.0.170.0000.00817.26
8.0.160.0070.00017.35
8.0.150.0000.00817.20
8.0.140.0060.00317.09
8.0.130.0030.00313.71
8.0.120.0000.00817.14
8.0.110.0040.00417.24
8.0.100.0040.00417.31
8.0.90.0000.00817.30
8.0.80.0070.01017.29
8.0.70.0000.00717.11
8.0.60.0040.00417.25
8.0.50.0030.00517.10
8.0.30.0110.00817.35
8.0.20.0120.00917.40
8.0.10.0000.00717.29
8.0.00.0130.00617.02
7.4.330.0050.00015.45
7.4.320.0000.00616.89
7.4.300.0000.00616.80
7.4.290.0040.00416.82
7.4.280.0040.00416.77
7.4.270.0070.00016.82
7.4.260.0000.00816.87
7.4.250.0000.00716.82
7.4.240.0030.00316.90
7.4.230.0040.00416.96
7.4.220.0100.00716.96
7.4.210.0070.00916.89
7.4.200.0000.00716.85
7.4.190.0070.00016.74
7.4.160.0080.00816.94
7.4.150.0100.00717.40
7.4.140.0040.01317.86
7.4.130.0070.01016.97
7.4.120.0080.01016.76
7.4.110.0070.01016.84
7.4.100.0100.00716.94
7.4.90.0060.01516.76
7.4.80.0140.00316.92
7.4.70.0100.00716.75
7.4.60.0100.01416.70
7.4.50.0040.00416.95
7.4.40.0070.01122.77
7.4.30.0100.00716.73
7.4.00.0090.00615.12
7.3.330.0030.00313.74
7.3.320.0000.00513.43
7.3.310.0070.00016.70
7.3.300.0030.00316.72
7.3.290.0070.01116.59
7.3.280.0080.01216.65
7.3.270.0080.00817.40
7.3.260.0090.01016.89
7.3.250.0130.00516.86
7.3.240.0130.01016.72
7.3.230.0130.00416.73
7.3.210.0060.01216.67
7.3.200.0070.01619.39
7.3.190.0080.00816.65
7.3.180.0060.01016.71
7.3.170.0080.00816.85
7.3.160.0030.01316.63
7.3.120.0060.01214.93
7.3.110.0080.01015.11
7.3.100.0100.00414.93
7.3.90.0040.00915.02
7.3.80.0070.00915.14
7.3.70.0060.00714.94
7.3.60.0060.00614.93
7.3.50.0050.01014.94
7.3.40.0060.00515.03
7.3.30.0030.01014.93
7.3.20.0050.00816.78
7.3.10.0060.00816.69
7.3.00.0070.00516.75
7.2.330.0130.00417.09
7.2.320.0030.01817.01
7.2.310.0120.00617.12
7.2.300.0030.01616.84
7.2.290.0090.00916.92
7.2.250.0120.00715.17
7.2.240.0070.01215.10
7.2.230.0080.01015.12
7.2.220.0020.01015.32
7.2.210.0100.00515.15
7.2.200.0040.00815.22
7.2.190.0070.00815.18
7.2.180.0060.00615.15
7.2.170.0040.01015.21
7.2.160.0120.00315.25
7.2.150.0030.00716.89
7.2.140.0090.00316.80
7.2.130.0100.00317.14
7.2.120.0070.00717.09
7.2.110.0000.01016.84
7.2.100.0070.00716.89
7.2.90.0040.01117.14
7.2.80.0070.00316.90
7.2.70.0120.00317.09
7.2.60.0070.00917.12
7.2.50.0100.00316.99
7.2.40.0100.00016.90
7.2.30.0070.00717.11
7.2.20.0060.00817.14
7.2.10.0060.00617.04
7.2.00.0120.00718.44
7.1.330.0060.00915.83
7.1.320.0040.00915.81
7.1.310.0100.00415.92
7.1.300.0030.01015.91
7.1.290.0050.01015.96
7.1.280.0040.00715.88
7.1.270.0090.00515.95
7.1.260.0040.01015.94
7.1.250.0040.00816.10
7.1.240.0000.01315.86
7.1.230.0030.00915.72
7.1.220.0040.00716.06
7.1.210.0040.00715.92
7.1.200.0030.01115.90
7.1.190.0130.00015.83
7.1.180.0000.01316.16
7.1.170.0000.01515.95
7.1.160.0080.00815.82
7.1.150.0090.00416.06
7.1.140.0080.00816.01
7.1.130.0090.00616.16
7.1.120.0070.00715.68
7.1.110.0030.01016.13
7.1.100.0030.00917.27
7.1.90.0090.00615.79
7.1.80.0030.01015.88
7.1.70.0030.00716.66
7.1.60.0120.00817.52
7.1.50.0100.00816.51
7.1.40.0000.01216.00
7.1.30.0120.00315.77
7.1.20.0100.00315.76
7.1.10.0030.01315.78
7.1.00.0040.04219.05
7.0.330.0060.00615.51
7.0.320.0070.00715.64
7.0.310.0040.01115.41
7.0.300.0090.00415.37
7.0.290.0000.01015.52
7.0.280.0100.00015.37
7.0.270.0060.00615.60
7.0.260.0000.01215.63
7.0.250.0030.00615.65
7.0.240.0000.00915.55
7.0.230.0070.00415.48
7.0.220.0040.00815.45
7.0.210.0100.00015.58
7.0.200.0060.00516.08
7.0.190.0060.00615.57
7.0.180.0000.01515.57
7.0.170.0050.00515.39
7.0.160.0100.00315.45
7.0.150.0000.01215.77
7.0.140.0000.04218.82
7.0.130.0110.00415.52
7.0.120.0040.01415.61
7.0.110.0030.01315.44
7.0.100.0060.01215.46
7.0.90.0030.00715.50
7.0.80.0030.01015.59
7.0.70.0120.00315.77
7.0.60.0070.04017.86
7.0.50.0080.03916.89
7.0.40.0070.04216.79
7.0.30.0200.02917.00
7.0.20.0160.02617.03
7.0.10.0060.04316.96
7.0.00.0120.02916.85
5.6.400.0060.00914.61
5.6.390.0030.01214.36
5.6.380.0150.00014.65
5.6.370.0060.00914.63
5.6.360.0030.01314.62
5.6.350.0070.00714.90
5.6.340.0130.00314.66
5.6.330.0090.00314.63
5.6.320.0070.00314.75
5.6.310.0100.00314.64
5.6.300.0040.01114.57
5.6.290.0040.00714.91
5.6.280.0070.03717.87
5.6.270.0090.00614.57
5.6.260.0060.01214.91
5.6.250.0030.00914.54
5.6.240.0040.01114.59
5.6.230.0090.00414.41
5.6.220.0150.00014.98
5.6.210.0050.04917.85
5.6.200.0090.02116.44
5.6.190.0080.04217.73
5.6.180.0230.02317.58
5.6.170.0170.02717.54
5.6.160.0050.04617.49
5.6.150.0060.04016.37
5.6.140.0050.03316.43
5.6.130.0090.02516.61
5.6.120.0070.02517.86
5.6.110.0170.04017.79
5.6.100.0050.04817.83
5.6.90.0000.03017.78
5.6.80.0090.03017.40
5.6.70.0000.01114.71
5.6.60.0090.00314.52
5.6.50.0060.00314.45
5.6.40.0090.00014.74
5.6.30.0000.01314.29
5.6.20.0030.01014.40
5.6.10.0030.00914.54
5.6.00.0040.01114.25
5.5.380.0080.00414.38
5.5.370.0000.01014.38
5.5.360.0090.00614.48
5.5.350.0090.04017.49
5.5.340.0080.02716.22
5.5.330.0070.04417.59
5.5.320.1550.02317.47
5.5.310.0110.02317.48
5.5.300.0100.04316.12
5.5.290.0070.04716.27
5.5.280.0100.03817.66
5.5.270.0110.04117.72
5.5.260.0050.04017.59
5.5.250.0050.03017.60
5.5.240.0080.04317.49
5.5.230.0030.00914.35
5.5.220.0060.00914.52
5.5.210.0060.00614.53
5.5.200.0070.00314.73
5.5.190.0030.00614.45
5.5.180.0000.01214.36
5.5.170.0160.00014.42
5.5.160.0080.00414.64
5.5.150.0100.00314.45
5.5.140.0090.00614.58
5.5.130.0090.00614.61
5.5.120.0100.00314.41
5.5.110.0030.01014.23
5.5.100.0060.00614.55
5.5.90.0000.01214.22
5.5.80.0090.00614.49
5.5.70.0060.00914.61
5.5.60.0090.00314.50
5.5.50.0030.01014.51
5.5.40.0060.00914.43
5.5.30.0090.00614.62
5.5.20.0000.01214.56
5.5.10.0030.01014.30
5.5.00.0100.00014.05
5.4.450.1670.02115.99
5.4.440.1600.02015.93
5.4.430.1720.01915.98
5.4.420.1550.03016.07
5.4.410.1790.01816.03
5.4.400.1670.02515.92
5.4.390.1790.02015.84
5.4.380.1730.02015.78
5.4.370.1730.02315.83
5.4.360.1580.02615.84
5.4.350.1850.02415.81
5.4.340.1770.01815.85
5.4.330.0000.00912.48
5.4.320.1720.02415.85
5.4.310.1750.01815.78
5.4.300.1700.02115.94
5.4.290.1760.02315.93
5.4.280.1760.02015.94
5.4.270.1600.02515.91
5.4.260.1630.02015.92
5.4.250.1730.01815.84
5.4.240.1810.01615.82
5.4.230.1570.02415.77
5.4.220.1780.02515.92
5.4.210.1920.02215.82
5.4.200.1700.02015.85
5.4.190.1760.02315.76
5.4.180.1720.02415.82
5.4.170.1710.02315.76
5.4.160.1800.02315.88
5.4.150.1970.02315.81
5.4.140.2130.02214.64
5.4.130.1430.02614.54
5.4.120.1540.01814.49
5.4.110.1630.01514.51
5.4.100.1500.02314.60
5.4.90.1650.02214.58
5.4.80.1370.02014.58
5.4.70.1580.02014.57
5.4.60.1570.02214.52
5.4.50.1600.01914.48
5.4.40.1570.01814.52
5.4.30.1800.01814.57
5.4.20.1730.02314.44
5.4.10.1150.01714.47
5.4.00.1780.01814.19
5.3.290.1750.02013.66
5.3.280.1730.02413.57
5.3.270.1680.02313.65
5.3.260.1620.02513.60
5.3.250.2080.02313.58
5.3.240.1750.02413.59
5.3.230.1630.02313.68
5.3.220.1300.01813.57
5.3.210.1670.02413.68
5.3.200.1530.02213.56
5.3.190.1530.02413.54
5.3.180.1620.01813.55
5.3.170.1580.02113.56
5.3.160.1420.02213.62
5.3.150.1700.02113.57
5.3.140.1510.02013.56
5.3.130.1720.02213.67
5.3.120.1620.02213.66
5.3.110.1860.02613.56
5.3.100.1750.02013.37
5.3.90.1870.02213.29
5.3.80.1600.02213.29
5.3.70.1780.02113.25
5.3.60.1750.02313.29
5.3.50.1760.02013.31
5.3.40.1770.02013.31
5.3.30.1730.02313.31
5.3.20.1730.02013.17
5.3.10.1620.02213.20
5.3.00.2260.02413.15
5.2.170.2970.03311.35
5.2.160.2670.03011.38
5.2.150.2770.03011.18
5.2.140.2970.02711.23
5.2.130.2970.02311.11
5.2.120.2770.02011.15
5.2.110.2670.03311.42
5.2.100.3030.03711.36
5.2.90.2870.02711.13
5.2.80.2600.03311.37
5.2.70.3300.03311.16
5.2.60.2770.03311.32
5.2.50.2870.03011.12
5.2.40.2330.03011.12
5.2.30.2470.03311.04
5.2.20.2370.02711.13
5.2.10.2130.02710.93
5.2.00.2130.03010.97
5.1.60.2300.02310.10
5.1.50.3200.02310.29
5.1.40.2300.02310.03
5.1.30.2400.02710.55
5.1.20.2400.02710.39
5.1.10.2500.02710.16
5.1.00.2400.02710.15
5.0.50.1270.0278.60
5.0.40.1430.0178.45
5.0.30.1200.0338.25
5.0.20.1170.0208.23
5.0.10.1400.0238.36
5.0.00.1200.0308.21
4.4.90.1330.0176.82
4.4.80.1230.0236.82
4.4.70.1230.0176.82
4.4.60.1300.0176.82
4.4.50.1170.0176.82
4.4.40.1130.0176.82
4.4.30.1330.0206.82
4.4.20.1470.0176.82
4.4.10.1230.0176.82
4.4.00.1170.0276.82
4.3.110.1470.0206.82
4.3.100.1330.0176.82
4.3.90.1130.0136.82
4.3.80.1330.0276.82
4.3.70.1170.0176.82
4.3.60.1330.0136.82
4.3.50.1300.0176.82
4.3.40.1500.0236.82
4.3.30.0670.0276.82
4.3.20.0600.0206.82
4.3.10.0700.0236.82
4.3.00.0530.0136.82

preferences:
41.28 ms | 401 KiB | 5 Q