3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convert($xml) { $simpleXmlObj = simplexml_load_string($xml); $simpleXmlObj = self::_fixVersionDifferences($simpleXmlObj); $array = self::_simpleXmlObj2Array($simpleXmlObj); return $array; } function _fixVersionDifferences($simpleXmlObj) { $simpleXmlObj = self::_fixEmptyStringDifference($simpleXmlObj); return $simpleXmlObj; } function _fixEmptyStringDifference($simpleXmlObj) { foreach (get_object_vars($simpleXmlObj) as $key => $element) { if ($element instanceof \SimpleXMLElement) { $simpleXmlObj->$key = self::_fixEmptyStringDifference($element); } if ($element != 0 && empty($element)) { unset($simpleXmlObj->$key); } } return $simpleXmlObj; } function _simpleXmlObj2Array($simpleXmlObj) { //Maybe it is not fast but the easiest way to convert return json_decode(json_encode($simpleXmlObj), TRUE); } $xml = <<<xml <?xml version="1.0" encoding="utf-8"?> <RESPONSE> <SUCCESS>true</SUCCESS> <ERRORMESSAGE> </ERRORMESSAGE> <TIMESTAMP>21/09/2015 03:26:37</TIMESTAMP> </RESPONSE> xml; $response = convert($xml); print_r($response);
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.29, 5.6.0 - 5.6.13
Fatal error: Cannot access self:: when no class scope is active in /in/GC0MO on line 6
Process exited with code 255.

preferences:
203.04 ms | 1395 KiB | 95 Q