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'][0]; 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.70.0120.00416.87
8.3.60.0120.00918.93
8.3.50.0130.01022.14
8.3.40.0140.00719.30
8.3.30.0090.00619.37
8.3.20.0040.00420.60
8.3.10.0080.00022.10
8.3.00.0040.00420.89
8.2.180.0100.01316.88
8.2.170.0110.00422.96
8.2.160.0100.00722.38
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00022.41
8.2.110.0030.00621.29
8.2.100.0090.00318.09
8.2.90.0090.00019.21
8.2.80.0060.00317.97
8.2.70.0070.00318.18
8.2.60.0000.00918.29
8.2.50.0040.00418.10
8.2.40.0000.00820.83
8.2.30.0050.00518.48
8.2.20.0000.00717.98
8.2.10.0080.00017.98
8.2.00.0130.00018.05
8.1.280.0100.01025.92
8.1.270.0080.00024.08
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00319.76
8.1.230.0030.00718.08
8.1.220.0080.00017.78
8.1.210.0040.00418.77
8.1.200.0030.00617.60
8.1.190.0000.00817.60
8.1.180.0050.00318.10
8.1.170.0050.00518.88
8.1.160.0040.00422.41
8.1.150.0040.00418.89
8.1.140.0070.00017.71
8.1.130.0040.00418.14
8.1.120.0000.01017.67
8.1.110.0000.00817.67
8.1.100.0020.00517.64
8.1.90.0000.00717.68
8.1.80.0040.00417.80
8.1.70.0040.00417.64
8.1.60.0060.00317.90
8.1.50.0040.00417.85
8.1.40.0000.00817.81
8.1.30.0040.00417.93
8.1.20.0000.00817.99
8.1.10.0080.00017.91
8.1.00.0000.00917.64
8.0.300.0000.00818.77
8.0.290.0060.00317.13
8.0.280.0040.00418.69
8.0.270.0050.00217.51
8.0.260.0030.00517.15
8.0.250.0030.00317.32
8.0.240.0030.00517.31
8.0.230.0000.00717.18
8.0.220.0000.00717.25
8.0.210.0080.00017.09
8.0.200.0060.00017.30
8.0.190.0000.00717.29
8.0.180.0050.00517.28
8.0.170.0040.00417.28
8.0.160.0040.00417.21
8.0.150.0000.00817.04
8.0.140.0040.00417.11
8.0.130.0030.00313.69
8.0.120.0040.00417.10
8.0.110.0000.00717.24
8.0.100.0000.00817.16
8.0.90.0050.00317.04
8.0.80.0080.00817.26
8.0.70.0000.00717.04
8.0.60.0070.00017.30
8.0.50.0000.00717.00
8.0.30.0150.00617.43
8.0.20.0130.00717.51
8.0.10.0040.00417.21
8.0.00.0100.01316.99
7.4.330.0000.00515.31
7.4.320.0000.00616.84
7.4.300.0030.00316.86
7.4.290.0050.00216.91
7.4.280.0000.00716.93
7.4.270.0030.00316.84
7.4.260.0070.00016.89
7.4.250.0040.00416.71
7.4.240.0060.00216.78
7.4.230.0050.00316.61
7.4.220.0070.01116.77
7.4.210.0080.00816.81
7.4.200.0030.00316.88
7.4.190.0040.00416.73
7.4.160.0070.01117.00
7.4.150.0120.00817.40
7.4.140.0090.01217.86
7.4.130.0080.01016.78
7.4.120.0090.00916.91
7.4.110.0000.01716.95
7.4.100.0080.00816.75
7.4.90.0130.00416.84
7.4.80.0060.01116.76
7.4.70.0080.00816.71
7.4.60.0040.01416.85
7.4.50.0060.00316.64
7.4.40.0060.00922.77
7.4.30.0090.01116.55
7.4.00.0070.00915.12
7.3.330.0000.00513.68
7.3.320.0000.00613.54
7.3.310.0030.00316.46
7.3.300.0030.00316.52
7.3.290.0060.01516.60
7.3.280.0050.01116.65
7.3.270.0090.00917.40
7.3.260.0100.01016.97
7.3.250.0180.00316.71
7.3.240.0160.00016.91
7.3.230.0120.00916.61
7.3.210.0060.01116.89
7.3.200.0070.01119.39
7.3.190.0060.01216.81
7.3.180.0040.01216.89
7.3.170.0060.01516.79
7.3.160.0090.00616.64
7.3.120.0050.01015.04
7.3.110.0070.01115.29
7.3.100.0090.00615.37
7.3.90.0000.01515.02
7.3.80.0130.00315.09
7.3.70.0030.00915.06
7.3.60.0070.00714.94
7.3.50.0040.01114.78
7.3.40.0090.00614.79
7.3.30.0070.01315.09
7.3.20.0130.00316.85
7.3.10.0050.00516.84
7.3.00.0030.01016.71
7.2.330.0100.00716.74
7.2.320.0220.00217.10
7.2.310.0100.00617.01
7.2.300.0060.01017.05
7.2.290.0070.01016.92
7.2.250.0100.00915.19
7.2.240.0000.01715.34
7.2.230.0100.00715.16
7.2.220.0080.00415.37
7.2.210.0040.01415.41
7.2.200.0090.00315.43
7.2.190.0040.00815.04
7.2.180.0000.01515.23
7.2.170.0100.00715.24
7.2.60.0080.00417.07
7.2.00.0070.00719.63
7.1.330.0000.01615.79
7.1.320.0070.00715.95
7.1.310.0040.01116.00
7.1.300.0050.00515.94
7.1.290.0030.00715.88
7.1.280.0060.01015.98
7.1.270.0060.01315.83
7.1.260.0000.01216.01
7.1.200.0000.01315.90
7.1.100.0030.00618.53
7.1.70.0030.00617.33
7.1.60.0090.01619.32
7.1.50.0130.01016.98
7.1.00.0000.09722.52
7.0.200.0030.00517.00
7.0.140.0030.07022.10
7.0.60.0030.06020.14
7.0.50.0170.07718.08
7.0.40.0130.03720.05
7.0.30.0200.03720.41
7.0.20.0230.07720.26
7.0.10.0030.09720.38
7.0.00.0100.07320.23
5.6.280.0030.07321.08
5.6.210.0000.08320.88
5.6.200.0070.08318.41
5.6.190.0200.04320.72
5.6.180.0030.08320.54
5.6.170.0430.05020.62
5.6.160.0000.04720.57
5.6.150.0070.07018.23
5.6.140.0100.08018.36
5.6.130.0000.04318.23
5.6.120.0130.07321.20
5.6.110.0130.08321.18
5.6.100.0000.04321.04
5.6.90.0130.03321.13
5.6.80.0130.07320.56
5.5.350.0000.04320.55
5.5.340.0070.08018.19
5.5.330.0070.08320.20
5.5.320.0070.07320.46
5.5.310.0370.07320.45
5.5.300.0030.08718.05
5.5.290.0000.05718.15
5.5.280.0130.07720.90
5.5.270.0030.06021.03
5.5.260.0100.08320.80
5.5.250.0000.06720.78
5.5.240.0070.07320.39
5.4.450.0670.04319.66
5.4.440.0500.05019.70
5.4.430.0400.03719.37
5.4.420.0300.05019.38
5.4.410.0630.03319.27
5.4.400.0230.04719.02
5.4.390.0430.06718.84
5.4.380.0130.06018.59
5.4.370.0100.06018.77
5.4.360.0130.06018.61
5.4.350.0170.04718.91
5.4.340.0230.04718.54
5.4.320.0080.03812.70
5.4.310.0040.04312.70
5.4.300.0100.03412.71
5.4.290.0090.03912.71
5.4.280.0070.04312.60
5.4.270.0060.04212.61
5.4.260.0070.04812.60
5.4.250.0090.04212.61
5.4.240.0060.03612.60
5.4.230.0050.04212.59
5.4.220.0060.03912.60
5.4.210.0060.03912.59
5.4.200.0050.04212.60
5.4.190.0160.04212.58
5.4.180.0130.04512.58
5.4.170.0190.03912.59
5.4.160.0180.04112.58
5.4.150.0360.08512.59
5.4.140.0170.04112.27
5.4.130.0140.04412.25
5.4.120.0140.04512.21
5.4.110.0140.04412.21
5.4.100.0150.04612.21
5.4.90.0160.04412.21
5.4.80.0280.06712.21
5.4.70.0190.04312.20
5.4.60.0170.04112.20
5.4.50.0340.08412.20
5.4.40.0180.03812.18
5.4.30.0170.04112.18
5.4.20.0120.04512.19
5.4.10.0150.04112.18
5.4.00.0190.03711.68
5.3.290.0050.04312.96
5.3.280.0050.04612.90
5.3.270.0180.04212.89
5.3.260.0190.04112.89
5.3.250.0230.06712.89
5.3.240.0160.04412.89
5.3.230.0160.04512.88
5.3.220.0160.04312.86
5.3.210.0260.03812.86
5.3.200.0210.04112.85
5.3.190.0210.04312.86
5.3.180.0160.04612.85
5.3.170.0160.04612.85
5.3.160.0160.04912.85
5.3.150.0160.04612.85
5.3.140.0320.08712.84
5.3.130.0150.04712.83
5.3.120.0210.04112.83
5.3.110.0180.04612.83
5.3.100.0150.04512.32
5.3.90.0150.04312.30
5.3.80.0140.04712.29
5.3.70.0230.04312.29
5.3.60.0250.06612.27
5.3.50.0160.04512.23
5.3.40.0160.04512.22
5.3.30.0170.04112.19
5.3.20.0120.04611.96
5.3.10.0160.03911.93
5.3.00.0190.03711.91
5.2.170.0150.0319.43
5.2.160.0100.0379.42
5.2.150.0090.0389.42
5.2.140.0120.0369.42
5.2.130.0130.0339.38
5.2.120.0120.0359.38
5.2.110.0250.0539.38
5.2.100.0110.0369.38
5.2.90.0140.0339.38
5.2.80.0090.0399.38
5.2.70.0120.0369.38
5.2.60.0080.0399.33
5.2.50.0160.0319.29
5.2.40.0110.0379.27
5.2.30.0150.0339.24
5.2.20.0110.0379.25
5.2.10.0100.0369.14
5.2.00.0110.0349.00
5.1.60.0250.0468.30
5.1.50.0120.0318.30
5.1.40.0110.0308.28
5.1.30.0130.0308.63
5.1.20.0140.0298.61
5.1.10.0110.0328.32
5.1.00.0150.0278.32
5.0.50.0090.0256.81
5.0.40.0110.0216.67
5.0.30.0110.0346.48
5.0.20.0120.0226.46
5.0.10.0100.0246.43
5.0.00.0060.0396.42
4.4.90.0110.0154.78
4.4.80.0080.0194.76
4.4.70.0090.0184.75
4.4.60.0070.0204.76
4.4.50.0060.0194.77
4.4.40.0080.0334.71
4.4.30.0100.0234.75
4.4.20.0130.0164.85
4.4.10.0060.0214.85
4.4.00.0120.0254.76
4.3.110.0110.0164.67
4.3.100.0090.0184.66
4.3.90.0110.0174.64
4.3.80.0080.0344.58
4.3.70.0110.0214.63
4.3.60.0160.0104.63
4.3.50.0080.0204.63
4.3.40.0080.0284.54
4.3.30.0030.0223.30
4.3.20.0040.0213.27
4.3.10.0050.0183.24
4.3.00.0000.01312.98

preferences:
58.02 ms | 401 KiB | 5 Q