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 LIBXML_DOTTED_VERSION, PHP_EOL, f($sample); function f(SimpleXMLElement $x) { $doc = dom_import_simplexml($x)->ownerDocument; $doc->formatOutput = true; return $doc->saveXML(); }
Output for 5.5.36 - 5.5.37, 5.6.22 - 5.6.28, 7.0.7 - 7.1.0
2.9.4 <?xml version="1.0"?> <root> <parent> <child1/> <child2/> </parent> </root>
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.21, 7.0.0 - 7.0.6
2.9.3 <?xml version="1.0"?> <root> <parent> <child1/> <child2/> </parent> </root>
Output for 5.4.0 - 5.4.45
2.9.2 <?xml version="1.0"?> <root> <parent> <child1/> <child2/> </parent> </root>
Output for 5.3.25 - 5.3.29
2.9.1 <?xml version="1.0"?> <root> <parent> <child1/> <child2/> </parent> </root>
Output for 5.3.15 - 5.3.24
2.8.0 <?xml version="1.0"?> <root> <parent> <child1/> <child2/> </parent> </root>
Output for 5.1.3 - 5.3.14
2.7.8 <?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/CueSv 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/CueSv on line 10
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/CueSv on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/CueSv on line 10
Process exited with code 255.