3v4l.org

run code in 300+ PHP versions simultaneously
<?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.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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.

preferences:
144.66 ms | 401 KiB | 188 Q