xref: /PHP-8.2/ext/dom/tests/bug36756.phpt (revision bd9f4fa6)
1--TEST--
2Bug #36756 (DOMDocument::removeChild corrupts node)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8/* Node is preserved from removeChild */
9$dom = new DOMDocument();
10$dom->loadXML('<root><child/></root>');
11$xpath = new DOMXpath($dom);
12$node = $xpath->query('/root')->item(0);
13echo $node->nodeName . "\n";
14$dom->removeChild($GLOBALS['dom']->firstChild);
15echo "nodeType: " . $node->nodeType . "\n";
16/* Node gets destroyed during removeChild */
17$dom->loadXML('<root><child/></root>');
18$xpath = new DOMXpath($dom);
19$node = $xpath->query('//child')->item(0);
20echo $node->nodeName . "\n";
21$GLOBALS['dom']->removeChild($GLOBALS['dom']->firstChild);
22
23try {
24    echo "nodeType: " . $node->nodeType . "\n";
25} catch (\Error $e) {
26    echo get_class($e) . ': ' . $e->getMessage() .\PHP_EOL;
27}
28
29?>
30--EXPECT--
31root
32nodeType: 1
33child
34Error: Couldn't fetch DOMElement. Node no longer exists
35