3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $sample = new SimpleXMLElement('<root><parent><child1></child1></parent></root>'); $node = $sample->xpath('//parent'); $node[0]->addChild('child2'); echo f($sample); function f(SimpleXMLElement $x) { $doc = dom_import_simplexml($x)->ownerDocument; $doc->formatOutput = true; return $doc->saveXML(); }
Output for 5.1.3 - 7.1.0
<?xml version="1.0"?> <root> <parent> <child1/> <child2/> </parent> </root>
Output for 5.0.0 - 5.1.2
Fatal error: Call to undefined method SimpleXMLElement::addChild() in /in/VR04Q on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/VR04Q on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting ')' in /in/VR04Q on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/VR04Q on line 9
Process exited with code 255.