3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function main() { $xml = '<foo><bar /></foo>'; $dom1 = new DOMDocument(); $dom1->loadXML($xml); $dom2 = clone $dom1; var_dump($dom1->firstChild->nodeName); var_dump($dom2->firstChild->nodeName); $child1 = $dom1->firstChild; $child2 = clone $child1; $child1->foo = 12; $child2->foo = 88; return array($dom1, $dom2, $child1, $child2); } list($x, $y, $c, $d) = main(); var_dump($x->firstChild->foo); var_dump($y->firstChild->foo);
based on r8EoN
Output for 5.2.6 - 7.2.0
string(3) "foo" string(3) "foo" int(12) Notice: Undefined property: DOMElement::$foo in /in/TM9fV on line 24 NULL
Output for 5.0.0 - 5.1.2, 5.1.4 - 5.2.5
string(3) "foo" string(3) "foo" int(12) Notice: Undefined property: DOMElement::$foo in /in/TM9fV on line 24 NULL
Output for 5.1.3
string(3) "foo" Warning: main(): Invalid State Error in /in/TM9fV on line 10 Notice: Trying to get property of non-object in /in/TM9fV on line 10 NULL int(12) Warning: main(): Invalid State Error in /in/TM9fV on line 24 Notice: Trying to get property of non-object in /in/TM9fV on line 24 NULL
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/TM9fV on line 7
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_VARIABLE in /in/TM9fV on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/TM9fV on line 7
Process exited with code 255.