3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<?xml version="1.0" encoding="utf-8" ?> <soap-env> <person name="Max Musterman"> <car marke="BMW" kennung="i8"/> <phone name="iPhone">9</phone> <birth-place>Hamburg</birth-place> <address> <street>Hauptstraße 1</street> <plz>245698</plz> </address> </person> <person name="Dr. Dolittle"> <car marke="Audi" kennung="A3"/> <phone name="Sony">Xperia Z3</phone> <birth-place>München</birth-place> <address> <street>Partkstraße</street> <plz>365494</plz> </address> </person> </soap-env>'; $doc = new DomDocument('1.0', 'utf-8'); $doc->loadXml($xml); final class Hydrator { private $callbacks = []; public function __construct(array $callbacks = []) { $this->setCallbacks($callbacks); } public function setCallback(string $nodeName, callable $callback): void { $this->callbacks[$nodeName] = $callback; } public function setCallbacks(array $callbacks): void { foreach ($callbacks as $nodeName => $callback) { $this->setCallback($nodeName, $callback); } } public function hydrate(DOMNode $node) { $this->apply($node); foreach ($node->childNodes as $child) { $this->hydrate($child); } } private function apply(DomNode $node) { if (array_key_exists($node->nodeName, $this->callbacks)) { print $callback($node, $this); } else { print $node->nodeName . PHP_EOL; } } } $hydrator = new Hydrator(); $hydrator->hydrate($doc->documentElement);
Output for 7.3.16 - 7.3.33, 7.4.4 - 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
soap-env #text person #text car #text phone #text #text birth-place #text #text address #text street #text #text plz #text #text #text #text person #text car #text phone #text #text birth-place #text #text address #text street #text #text plz #text #text #text #text
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 soap-env #text person #text car #text phone #text #text birth-place #text #text address #text street #text #text plz #text #text #text #text person #text car #text phone #text #text birth-place #text #text address #text street #text #text plz #text #text #text #text
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.1, 7.4.0 - 7.4.3
soap-env #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 person #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 car #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 phone #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 birth-place #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 address #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 street #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 plz #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 person #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 car #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 phone #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 birth-place #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 address #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 street #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 plz #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53 #text Warning: Invalid argument supplied for foreach() in /in/ufdvr on line 53
Output for 7.0.0 - 7.0.31
Fatal error: Uncaught TypeError: Return value of Hydrator::setCallbacks() must be an instance of void, none returned in /in/ufdvr:47 Stack trace: #0 /in/ufdvr(34): Hydrator->setCallbacks(Array) #1 /in/ufdvr(68): Hydrator->__construct() #2 {main} thrown in /in/ufdvr on line 47
Process exited with code 255.

preferences:
201.54 ms | 401 KiB | 211 Q