3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $domDoc = new DOMDocument; $domDoc->preserveWhiteSpace=false; $rootNode = $domDoc->documentElement; $config_root = $rootNode->getElementsByTagName("CONFIG"); $rootElt = $domDoc->createElement('USER-ID'); $subNode = $rootNode->appendChild($rootElt); $textNode = $domDoc->createTextNode('333265332f'); $subNode->appendChild($textNode); $rootElt = $domDoc->createElement('USER-NAME'); $sub2Node = $rootNode->appendChild($rootElt); $textNode = $domDoc->createTextNode('John'); $sub2Node->appendChild($textNode); $domDoc->formatOutput = true; //$domDoc->save('config.xml'); echo $domDoc->saveXML();
based on AZqpf
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to a member function getElementsByTagName() on null in /in/XEJVe:6 Stack trace: #0 {main} thrown in /in/XEJVe on line 6
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Fatal error: Call to a member function getElementsByTagName() on null in /in/XEJVe on line 6
Process exited with code 255.
Output for 5.3.19 - 5.5.35
Fatal error: Call to a member function getElementsByTagName() on a non-object in /in/XEJVe on line 6
Process exited with code 255.