3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function fromXML(XMLReader $xml) { $node = []; while ($xml->read()) { if (!$xml->isValid()) { $xmlErrors = libxml_get_errors(); $errorLines = array(); foreach ($xmlErrors as $error) { $errorLines[] = 'Line: ' . $error->line . ' Column: ' . $error->column . ' - ' . $error->message; } throw new Exception(join("", $errorLines)); } switch ($xml->nodeType) { case XMLReader::END_ELEMENT: return (count($node) > 0) ? $node : null; case XMLReader::ELEMENT: $node[$xml->name] = ($xml->isEmptyElement ? '' : $this->fromXML($xml)); break; case XMLReader::TEXT: case XMLReader::CDATA: $node = $xml->value; break; } } return $node; } $data = '<?xml version="1.0" encoding="UTF-8"?> <request> <header> <version>0.6</version> <dateTime>2017-07-05T11:21:46</dateTime> <sender>PROVIDER</sender> <recipient>dfsafdaf</recipient> <messageType>isvalid</messageType> </header> <voucher> <voucherId>1</voucherId> </voucher> </request>'; $xml = new XMLReader(); $xml->xml($data); var_dump(fromXML($xml));
Output for 7.0.0 - 7.3.0rc3
Fatal error: Uncaught Exception in /in/Kio8P:13 Stack trace: #0 /in/Kio8P(47): fromXML(Object(XMLReader)) #1 {main} thrown in /in/Kio8P on line 13
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught exception 'Exception' with message '' in /in/Kio8P:13 Stack trace: #0 /in/Kio8P(47): fromXML() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Uncaught exception 'Exception' in /in/Kio8P:13 Stack trace: #0 /in/Kio8P(47): fromXML(Object(XMLReader)) #1 {main} thrown in /in/Kio8P on line 13
Process exited with code 255.