3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); class XML { var $parser; #a reference to the XML parser var $document; #the entire XML structure built up so far var $current; #a pointer to the current item - what is this var $parent; #a pointer to the current parent - the parent will be an array var $parents; #an array of the most recent parent at each level var $last_opened_tag; function XML($data=null){ $this->parser = xml_parser_create(); xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "open", "close"); xml_set_character_data_handler($this->parser, "data"); # register_shutdown_function(array(&$this, 'destruct')); } function destruct(){ xml_parser_free($this->parser); } function parse($data){ $this->document = array(); $this->parent = &$this->document; $this->parents = array(); $this->last_opened_tag = NULL; xml_parse($this->parser, $data); return $this->document; } function open($parser, $tag, $attributes){ #echo "Opening tag $tag<br>\n"; $this->data = ""; $this->last_opened_tag = $tag; #tag is a string if(array_key_exists($tag, $this->parent)){ #echo "There's already an instance of '$tag' at the current level ($level)<br>\n"; if(is_array($this->parent[$tag]) and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric #need to make sure they're numeric (account for attributes) $key = count_numeric_items($this->parent[$tag]); #echo "There are $key instances: the keys are numeric.<br>\n"; }else{ #echo "There is only one instance. Shifting everything around<br>\n"; $temp = &$this->parent[$tag]; unset($this->parent[$tag]); $this->parent[$tag][0] = &$temp; if(array_key_exists("$tag attr", $this->parent)){ #shift the attributes around too if they exist $temp = &$this->parent["$tag attr"]; unset($this->parent["$tag attr"]); $this->parent[$tag]["0 attr"] = &$temp; } $key = 1; } $this->parent = &$this->parent[$tag]; }else{ $key = $tag; } if($attributes){ $this->parent["$key attr"] = $attributes; } $this->parent[$key] = array(); $this->parent = &$this->parent[$key]; $x = &$this->parent; array_unshift($this->parents, $x); } function data($parser, $data){ #echo "Data is '", htmlspecialchars($data), "'<br>\n"; if($this->last_opened_tag != NULL){ $this->data .= $data; } } function close($parser, $tag){ #echo "Close tag $tag<br>\n"; if($this->last_opened_tag == $tag){ $this->parent = $this->data; $this->last_opened_tag = NULL; } array_shift($this->parents); $this->parent = &$this->parents[0]; } }

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.00316.63
8.3.50.0090.00622.82
8.3.40.0070.01418.69
8.3.30.0030.01019.00
8.3.20.0000.00820.21
8.3.10.0030.00523.66
8.3.00.0060.00319.08
8.2.180.0120.00316.32
8.2.170.0060.00922.96
8.2.160.0070.00720.29
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0050.00321.05
8.2.110.0060.00320.48
8.2.100.0080.00318.06
8.2.90.0000.00818.96
8.2.80.0030.00517.97
8.2.70.0000.00817.50
8.2.60.0040.00417.80
8.2.50.0030.00618.07
8.2.40.0040.00418.09
8.2.30.0040.00419.49
8.2.20.0040.00417.61
8.2.10.0080.00018.04
8.2.00.0000.00717.49
8.1.280.0140.00725.92
8.1.270.0090.00023.84
8.1.260.0030.00326.35
8.1.250.0040.00428.09
8.1.240.0050.00522.04
8.1.230.0080.00319.17
8.1.220.0020.00517.74
8.1.210.0050.00318.77
8.1.200.0030.00617.22
8.1.190.0040.00417.10
8.1.180.0040.00418.10
8.1.170.0050.00518.59
8.1.160.0040.00421.98
8.1.150.0070.00018.80
8.1.140.0000.00717.40
8.1.130.0030.00317.86
8.1.120.0000.00717.29
8.1.110.0060.00317.37
8.1.100.0000.00717.39
8.1.90.0040.00417.29
8.1.80.0000.00717.34
8.1.70.0000.00717.38
8.1.60.0040.00417.39
8.1.50.0000.00817.48
8.1.40.0050.00217.33
8.1.30.0030.00617.53
8.1.20.0070.00017.57
8.1.10.0030.00517.42
8.1.00.0040.00417.35
8.0.300.0040.00418.77
8.0.290.0040.00416.63
8.0.280.0090.00018.32
8.0.270.0070.00017.15
8.0.260.0030.00317.26
8.0.250.0030.00316.79
8.0.240.0050.00316.79
8.0.230.0000.00716.76
8.0.220.0070.00316.82
8.0.210.0070.00016.80
8.0.200.0040.00416.87
8.0.190.0030.00616.85
8.0.180.0070.00016.79
8.0.170.0050.00316.92
8.0.160.0040.00416.81
8.0.150.0030.00516.74
8.0.140.0000.00816.84
8.0.130.0030.00313.28
8.0.120.0040.00416.76
8.0.110.0050.00216.79
8.0.100.0000.00816.70
8.0.90.0040.00416.65
8.0.80.0070.01016.77
8.0.70.0030.00616.69
8.0.60.0000.00916.69
8.0.50.0070.00016.66
8.0.30.0090.01617.19
8.0.20.0120.00617.40
8.0.10.0070.00016.92
8.0.00.0040.01316.71
7.4.330.0050.00015.02
7.4.320.0030.00316.47
7.4.300.0030.00316.53
7.4.290.0030.00316.40
7.4.280.0070.00016.43
7.4.270.0030.00316.33
7.4.260.0000.00916.43
7.4.250.0040.00416.48
7.4.240.0000.00716.53
7.4.230.0060.00016.36
7.4.220.0040.01516.55
7.4.210.0100.00716.61
7.4.200.0000.00716.36
7.4.160.0040.01216.36
7.4.150.0090.00917.40
7.4.140.0040.01417.86
7.4.130.0080.00916.48
7.4.120.0110.00616.46
7.4.110.0090.00916.35
7.4.100.0100.00716.45
7.4.90.0040.01816.50
7.4.80.0140.01419.39
7.4.70.0070.01016.27
7.4.60.0130.00316.43
7.4.50.0060.00316.62
7.4.40.0120.00416.55
7.4.30.0100.01416.38
7.4.00.0030.00915.11
7.3.330.0020.00213.13
7.3.320.0060.00013.21
7.3.310.0000.00716.32
7.3.300.0070.00016.16
7.3.290.0030.01316.28
7.3.280.0070.01016.31
7.3.270.0180.00617.40
7.3.260.0090.00916.23
7.3.250.0140.01016.29
7.3.240.0120.00816.43
7.3.230.0100.00716.39
7.3.210.0130.00316.36
7.3.200.0150.00319.39
7.3.190.0120.00616.44
7.3.180.0070.01016.38
7.3.170.0080.00816.41
7.3.160.0090.00616.47
7.2.330.0140.00316.57
7.2.320.0030.01516.61
7.2.310.0100.00716.61
7.2.300.0070.01016.30
7.2.290.0100.01316.48
7.2.60.0030.01016.23
7.2.50.0060.01116.57
7.1.200.0040.01115.79
7.1.70.0050.00317.14
7.1.60.0060.01919.46
7.1.50.0040.01116.95
7.1.00.0070.07322.35
7.0.200.0040.00416.64
7.0.140.0000.07322.18
7.0.60.0030.08019.91
7.0.50.0070.08317.89
7.0.40.0170.08020.30
7.0.30.0170.04320.21
7.0.20.0270.05020.33
7.0.10.0130.05020.28
7.0.00.0070.06020.10
5.6.280.0130.06320.96
5.6.210.0070.05320.55
5.6.200.0000.04718.15
5.6.190.0030.06020.61
5.6.180.0470.07720.64
5.6.170.0300.04720.39
5.6.160.0100.08320.52
5.6.150.0100.07718.25
5.6.140.0070.03718.17
5.6.130.0100.06018.20
5.6.120.0130.05720.87
5.6.110.0100.03721.03
5.6.100.0030.07021.00
5.6.90.0030.07721.12
5.6.80.0030.04020.40
5.5.350.0330.06320.36
5.5.340.0000.04317.99
5.5.330.0070.08720.47
5.5.320.0300.05020.36
5.5.310.0230.03320.35
5.5.300.0070.08018.04
5.5.290.0130.07318.07
5.5.280.0100.03720.79
5.5.270.0100.07320.88
5.5.260.0070.06021.00
5.5.250.0030.07320.73
5.5.240.0270.07320.39
5.4.450.0400.04319.46
5.4.440.0270.04019.55
5.4.430.1330.04719.32
5.4.420.0430.04319.38
5.4.410.0170.04019.42
5.4.400.0270.04019.02
5.4.390.0030.03318.95
5.4.380.0300.06018.75
5.4.370.0170.06718.70
5.4.360.0400.04318.75
5.4.350.0300.07718.75
5.4.340.0400.06718.59
5.4.320.0090.04112.52
5.4.310.0080.04412.52
5.4.300.0090.04012.52
5.4.290.0070.04512.52
5.4.280.0050.04512.42
5.4.270.0080.03812.41
5.4.260.0080.03612.41
5.4.250.0060.04112.41
5.4.240.0050.04212.41
5.4.230.0060.03812.41
5.4.220.0070.03912.41
5.4.210.0090.03412.40
5.4.200.0070.04112.41
5.4.190.0070.04512.40
5.4.180.0120.03812.41
5.4.170.0040.04012.42
5.4.160.0080.03912.41
5.4.150.0080.03612.40
5.4.140.0060.03712.09
5.4.130.0070.04412.08
5.4.120.0080.04012.04
5.4.110.0090.03512.03
5.4.100.0030.03912.03
5.4.90.0050.03812.03
5.4.80.0100.03312.03
5.4.70.0050.04412.03
5.4.60.0060.03412.03
5.4.50.0080.04212.03
5.4.40.0090.03212.02
5.4.30.0070.03712.02
5.4.20.0090.03212.02
5.4.10.0080.03912.02
5.4.00.0060.03511.50
5.3.290.0090.03712.80
5.3.280.0070.03912.71
5.3.270.0080.04312.72
5.3.260.0060.03912.72
5.3.250.0050.03812.72
5.3.240.0090.03412.72
5.3.230.0080.04212.71
5.3.220.0070.03712.68
5.3.210.0050.04112.68
5.3.200.0110.03612.68
5.3.190.0050.03912.68
5.3.180.0030.04312.68
5.3.170.0060.05112.68
5.3.160.0070.04012.67
5.3.150.0080.03712.68
5.3.140.0080.03712.66
5.3.130.0060.04712.66
5.3.120.0060.04012.66
5.3.110.0100.03712.66
5.3.100.0070.03912.15
5.3.90.0100.03312.13
5.3.80.0070.03912.12
5.3.70.0070.04412.12
5.3.60.0070.03912.11
5.3.50.0070.04212.05
5.3.40.0070.03812.05
5.3.30.0070.04512.01
5.3.20.0090.03411.79
5.3.10.0070.03511.76
5.3.00.0090.03511.74
5.2.170.0040.0339.25
5.2.160.0020.0359.25
5.2.150.0040.0339.25
5.2.140.0090.0369.25
5.2.130.0100.0359.21
5.2.120.0050.0299.20
5.2.110.0030.0319.21
5.2.100.0040.0319.21
5.2.90.0040.0299.21
5.2.80.0040.0319.20
5.2.70.0060.0319.20
5.2.60.0060.0309.16
5.2.50.0040.0339.13
5.2.40.0040.0309.11
5.2.30.0040.0329.08
5.2.20.0060.0329.07
5.2.10.0040.0308.98
5.2.00.0050.0348.83
5.1.60.0030.0288.13
5.1.50.0030.0268.13
5.1.40.0010.0308.11
5.1.30.0060.0248.45
5.1.20.0060.0268.48
5.1.10.0080.0258.20
5.1.00.0060.0248.20
5.0.50.0060.0196.68
5.0.40.0040.0206.54
5.0.30.0020.0336.36
5.0.20.0050.0186.32
5.0.10.0040.0206.30
5.0.00.0020.0336.29
4.4.90.0030.0164.78
4.4.80.0030.0154.75
4.4.70.0040.0164.75
4.4.60.0030.0154.75
4.4.50.0030.0154.77
4.4.40.0030.0254.70
4.4.30.0010.0184.76
4.4.20.0030.0164.84
4.4.10.0030.0164.85
4.4.00.0050.0234.76
4.3.110.0040.0154.66
4.3.100.0040.0144.66
4.3.90.0060.0114.63
4.3.80.0010.0264.59
4.3.70.0030.0144.63
4.3.60.0000.0174.63
4.3.50.0020.0174.63
4.3.40.0020.0254.54
4.3.30.0060.0123.34
4.3.20.0030.0163.32
4.3.10.0020.0163.29
4.3.00.0100.01718.56

preferences:
42.69 ms | 401 KiB | 5 Q