3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = '<user><prop name="A"><sub name="X"></sub></prop><prop name="B"><sub name="Y"></sub></prop></user>'; $xml = new DomDocument; $xml->loadXML($data); $xpath = new DomXpath($xml); $subY = $xpath->query('//sub[@name="Y"]'); $design = $doc->createElement('design', $xml); $design->setAttribute('name', 'J'); $design->setAttribute('path', 'folder'); $subY->appendChild($design); echo $xml->saveXML();
Output for 7.0.5 - 7.2.6
Notice: Undefined variable: doc in /in/a2PMm on line 11 Fatal error: Uncaught Error: Call to a member function createElement() on null in /in/a2PMm:11 Stack trace: #0 {main} thrown in /in/a2PMm on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Notice: Undefined variable: doc in /in/a2PMm on line 11 Fatal error: Uncaught Error: Call to a member function createElement() on unknown in /in/a2PMm:11 Stack trace: #0 {main} thrown in /in/a2PMm on line 11
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Notice: Undefined variable: doc in /in/a2PMm on line 11 Fatal error: Call to a member function createElement() on null in /in/a2PMm on line 11
Process exited with code 255.
Output for 5.0.4 - 5.5.38
Notice: Undefined variable: doc in /in/a2PMm on line 11 Fatal error: Call to a member function createElement() on a non-object in /in/a2PMm on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: doc in /in/a2PMm on line 11 Fatal error: Call to a member function createElement() on a non-object in /in/a2PMm on line 11
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/a2PMm on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/a2PMm on line 4