3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dom = new DOMDocument(); $root = $dom->createElement('html'); $dom->appendChild($root); $el1 = $dom->createElement('p1'); $el1->setAttribute('id', 'foo'); $el1->setIdAttribute('id', true); $root->appendChild($el1); $el2 = $dom->createElement('p2'); $el2->setAttribute('id', 'foo'); $el2->setIdAttribute('id', true); $root->appendChild($el2); unset($el1, $el2); $root->removeChild($dom->getElementById('foo')); var_dump($dom->getElementById('foo'));
Output for 8.4.1 - 8.4.12
object(DOMElement)#4 (27) { ["tagName"]=> string(2) "p2" ["className"]=> string(0) "" ["id"]=> string(3) "foo" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> NULL ["nodeName"]=> string(2) "p2" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> NULL ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(2) "p2" ["baseURI"]=> NULL ["textContent"]=> string(0) "" }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25
NULL

preferences:
147.38 ms | 409 KiB | 5 Q