3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ObjectAndXML { private static $xml; // Constructor public function __construct() { $this->xml = new XmlWriter(); $this->xml->openMemory(); $this->xml->startDocument('1.0'); $this->xml->setIndent(true); } // Method to convert Object into XML string public function objToXML($obj) { $this->getObject2XML($this->xml, $obj); $this->xml->endElement(); return $this->xml->outputMemory(true); } // Method to convert XML string into Object public function xmlToObj($xmlString) { return simplexml_load_string($xmlString); } private function getObject2XML(XMLWriter $xml, $data) { foreach($data as $key => $value) { if(is_object($value)) { $xml->startElement($key); $this->getObject2XML($xml, $value); $xml->endElement(); continue; } else if(is_array($value)) { $this->getArray2XML($xml, $key, $value); } if (is_string($value)) { $xml->writeElement($key, $value); } } } private function getArray2XML(XMLWriter $xml, $keyParent, $data) { foreach($data as $key => $value) { if (is_string($value)) { $xml->writeElement($keyParent, $value); continue; } if (is_numeric($key)) { $xml->startElement($keyParent); } if(is_object($value)) { $this->getObject2XML($xml, $value); } else if(is_array($value)) { $this->getArray2XML($xml, $key, $value); continue; } if (is_numeric($key)) { $xml->endElement(); } } } } $obj = new ObjectAndXML(); $str = <<<STR <?xml version="1.0" encoding="utf-8"?> <records> <person> <name>XYZ</name> <age>28</age> <gender>Male</gender> </person> <person> <name>ABC</name> <age>25</age> <gender>Male</gender> </person> <attr> <a id="2">2</a> <a id="3">3</a> </attr> </records> STR; $recordsObj = $obj->xmlToObj($str); echo '<pre>'; var_dump($recordsObj);

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.0040.01517.00
8.3.50.0100.01318.31
8.3.40.0040.01219.10
8.3.30.0040.01119.00
8.3.20.0040.00420.46
8.3.10.0040.00423.92
8.3.00.0040.00419.63
8.2.180.0040.01118.79
8.2.170.0040.01122.96
8.2.160.0070.00720.70
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0000.00919.48
8.2.120.0080.00026.35
8.2.110.0070.00321.19
8.2.100.0060.00618.00
8.2.90.0000.00819.45
8.2.80.0040.00417.97
8.2.70.0090.00017.63
8.2.60.0030.00518.16
8.2.50.0070.00318.07
8.2.40.0000.00819.66
8.2.30.0070.00021.07
8.2.20.0000.01017.88
8.2.10.0000.00818.36
8.2.00.0060.00318.38
8.1.280.0060.01225.92
8.1.270.0060.00323.93
8.1.260.0080.00028.09
8.1.250.0040.00428.09
8.1.240.0080.00022.44
8.1.230.0080.00418.02
8.1.220.0000.00818.03
8.1.210.0000.00818.77
8.1.200.0030.00617.60
8.1.190.0030.00517.99
8.1.180.0030.00518.10
8.1.170.0080.00018.89
8.1.160.0040.00422.18
8.1.150.0030.00519.15
8.1.140.0060.00319.83
8.1.130.0000.00718.00
8.1.120.0000.00717.80
8.1.110.0030.00617.70
8.1.100.0000.00817.57
8.1.90.0040.00417.70
8.1.80.0040.00417.72
8.1.70.0060.00317.65
8.1.60.0050.00317.94
8.1.50.0040.00417.81
8.1.40.0030.00517.79
8.1.30.0000.00817.96
8.1.20.0000.00817.82
8.1.10.0040.00417.89
8.1.00.0030.00517.75
8.0.300.0040.00418.77
8.0.290.0050.00217.13
8.0.280.0000.00718.74
8.0.270.0040.00417.48
8.0.260.0000.00717.57
8.0.250.0040.00417.30
8.0.240.0030.00317.25
8.0.230.0050.00317.11
8.0.220.0000.01017.30
8.0.210.0030.00517.05
8.0.200.0030.00517.27
8.0.190.0080.00017.29
8.0.180.0000.00717.25
8.0.170.0030.00517.24
8.0.160.0040.00417.23
8.0.150.0030.00717.14
8.0.140.0000.00717.12
8.0.130.0000.00713.55
8.0.120.0030.00517.23
8.0.110.0060.00317.04
8.0.100.0070.00017.25
8.0.90.0080.00017.20
8.0.80.0100.00617.06
8.0.70.0030.00617.22
8.0.60.0080.00017.32
8.0.50.0050.00216.97
8.0.30.0150.00617.54
8.0.20.0090.01117.42
8.0.10.0030.00517.29
8.0.00.0060.01217.22
7.4.330.0020.00216.95
7.4.320.0000.00716.60
7.4.300.0070.00016.70
7.4.290.0050.00316.89
7.4.280.0040.00416.73
7.4.270.0070.00016.71
7.4.260.0030.00716.78
7.4.250.0060.00316.64
7.4.240.0040.00416.84
7.4.230.0040.00416.91
7.4.220.0130.00716.95
7.4.210.0100.00616.83
7.4.200.0000.00816.97
7.4.160.0070.01016.71
7.4.150.0060.02017.40
7.4.140.0080.01517.86
7.4.130.0060.01216.80
7.4.120.0150.00617.02
7.4.110.0150.00316.75
7.4.100.0150.00616.99
7.4.90.0090.00916.84
7.4.80.0110.00819.39
7.4.70.0030.01516.93
7.4.60.0100.00616.75
7.4.50.0070.01016.57
7.4.40.0100.00716.59
7.4.30.0030.01416.86
7.4.00.0060.00614.82
7.3.330.0000.00613.44
7.3.320.0030.00313.63
7.3.310.0040.00416.73
7.3.300.0000.00716.49
7.3.290.0000.00816.67
7.3.280.0120.00816.64
7.3.270.0130.00617.40
7.3.260.0100.01316.88
7.3.250.0150.01316.69
7.3.240.0130.00616.67
7.3.230.0190.00316.86
7.3.210.0060.01316.90
7.3.200.0110.01116.65
7.3.190.0150.01016.86
7.3.180.0070.01416.80
7.3.170.0170.00716.63
7.3.160.0060.01016.67
7.2.330.0060.01216.71
7.2.320.0100.01116.95
7.2.310.0120.01217.02
7.2.300.0150.00316.95
7.2.290.0110.01217.05
7.2.60.0190.00516.54
7.2.00.0140.00319.59
7.1.200.0040.00715.96
7.1.100.0070.00318.14
7.1.70.0050.00217.33
7.1.60.0040.01919.36
7.1.50.0090.01316.92
7.1.00.0030.07722.41
7.0.200.0070.00317.01
7.0.60.0100.08020.12
7.0.50.0130.07718.11
7.0.40.0230.06020.49
7.0.30.0530.06720.31
7.0.20.0400.08020.32
7.0.10.0170.08320.32
7.0.00.0230.05720.22
5.6.280.0070.05721.09
5.6.210.0070.05720.89
5.6.200.0000.04318.24
5.6.190.0130.06320.57
5.6.180.0200.04320.79
5.6.170.0330.04720.62
5.6.160.0100.03720.62
5.6.150.0100.05718.36
5.6.140.0130.07318.36
5.6.130.0070.08318.23
5.6.120.0070.06021.23
5.6.110.0100.04021.19
5.6.100.0100.08021.13
5.6.90.0130.08021.03
5.6.80.0070.08020.61
5.5.350.0200.07320.51
5.5.340.0070.08018.07
5.5.330.0070.06020.57
5.5.320.0300.04020.41
5.5.310.0230.06720.51
5.5.300.0130.07718.08
5.5.290.0130.07318.07
5.5.280.0170.07720.83
5.5.270.0030.05021.00
5.5.260.0030.04021.04
5.5.250.0000.08320.75
5.5.240.0270.06020.26

preferences:
47.3 ms | 400 KiB | 5 Q