xref: /PHP-8.2/ext/dom/tests/bug77686.phpt (revision 0e34ac86)
1--TEST--
2Bug #77686 (Removed elements are still returned by getElementById)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$doc = new DOMDocument;
9$doc->loadHTML('<html id="htmlelement"><body id="x">before<div id="y">hello</div>after</body></html>');
10$body = $doc->getElementById('x');
11$div = $doc->getElementById('y');
12var_dump($doc->getElementById('y')->textContent);
13
14// Detached from document, should not find it anymore
15$body->removeChild($div);
16var_dump($doc->getElementById('y'));
17
18// Added again, should find it
19$body->appendChild($div);
20var_dump($doc->getElementById('y')->textContent);
21
22// Should find root element without a problem
23var_dump($doc->getElementById('htmlelement')->textContent);
24
25// Created element but not yet attached, should not find it before it is added
26$new_element = $doc->createElement('p');
27$new_element->textContent = 'my new text';
28$new_element->setAttribute('id', 'myp');
29var_dump($doc->getElementById('myp'));
30$body->appendChild($new_element);
31var_dump($doc->getElementById('myp')->textContent);
32
33?>
34--EXPECT--
35string(5) "hello"
36NULL
37string(5) "hello"
38string(16) "beforeafterhello"
39NULL
40string(11) "my new text"
41