3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $foo1 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root />'); $foo1->addChild("x", htmlspecialchars("<test />")); $foo2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root><x /></root>'); $foo2->x = htmlspecialchars("<test />"); var_dump($foo1->x); var_dump($foo2->x); var_dump($foo1->asXML() === $foo2->asXML());
Output for 5.2.6 - 7.1.0
object(SimpleXMLElement)#3 (1) { [0]=> string(8) "<test />" } object(SimpleXMLElement)#3 (1) { [0]=> string(14) "&lt;test /&gt;" } bool(false)
Output for 5.1.3 - 5.2.5
object(SimpleXMLElement)#3 (1) { [0]=> string(8) "<test />" } object(SimpleXMLElement)#3 (1) { [0]=> string(8) "<test />" } bool(true)
Output for 5.0.0 - 5.1.2
Fatal error: Call to undefined method SimpleXMLElement::addChild() in /in/vv8CB on line 4
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/vv8CB on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/vv8CB on line 3