3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $aDOM = new DOMDocument(); $aDOM->loadXML('<f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o>'); echo 'Initial DOM is '.$aDOM->saveXML().chr(13); $newNode= $aDOM->createElementNS(" http://friend2friend.net ", 'newnode'); $newNode->appendChild($aDOM->documentElement); echo 'Appending the document Element to f2f:newnode, it all looks OK: '.chr(13).$aDOM->saveXML($newNode).chr(13).chr(13); $aDOM->appendChild($newNode); echo 'But adding <f2f:newnode> back as the documentElement changes a namespace '.$aDOM->saveXML();
Output for 7.1.0
Warning: DOMDocument::loadXML(): xmlns:f2f: ' http://friend2friend.net ' is not a valid URI in Entity, line: 1 in /in/93fde on line 3 Notice: DOMDocument::loadXML(): xmlns: URI default is not absolute in Entity, line: 1 in /in/93fde on line 3 Initial DOM is <?xml version="1.0"?> <f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o> Appending the document Element to f2f:newnode, it all looks OK: <newnode xmlns=" http://friend2friend.net "><f2f:o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><f2f:watch-me/></default:i></f2f:o></newnode> But adding <f2f:newnode> back as the documentElement changes a namespace <?xml version="1.0"?> <newnode xmlns=" http://friend2friend.net " xmlns:default="default"><o xmlns:f2f=" http://friend2friend.net " xmlns:default="default"><default:i xmlns="default"><watch-me/></default:i></o></newnode>