mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
Change the way lifetime works in ext/libxml and ext/dom Previously, a node could be freed even when holding a userland reference to it. This resulted in exceptions when trying to access that node after it has been implicitly or explicitly removed. After this patch, a node will only be freed when the last userland reference disappears. Fixes GH-9628. Closes GH-11576.
31 lines
734 B
PHP
31 lines
734 B
PHP
--TEST--
|
|
Bug #36756 (DOMDocument::removeChild corrupts node)
|
|
--EXTENSIONS--
|
|
dom
|
|
--FILE--
|
|
<?php
|
|
|
|
/* Node is preserved from removeChild */
|
|
$dom = new DOMDocument();
|
|
$dom->loadXML('<root><child/></root>');
|
|
$xpath = new DOMXpath($dom);
|
|
$node = $xpath->query('/root')->item(0);
|
|
echo $node->nodeName . "\n";
|
|
$dom->removeChild($GLOBALS['dom']->firstChild);
|
|
echo "nodeType: " . $node->nodeType . "\n";
|
|
/* Node gets destroyed during removeChild */
|
|
$dom->loadXML('<root><child/></root>');
|
|
$xpath = new DOMXpath($dom);
|
|
$node = $xpath->query('//child')->item(0);
|
|
echo $node->nodeName . "\n";
|
|
$GLOBALS['dom']->removeChild($GLOBALS['dom']->firstChild);
|
|
|
|
echo "nodeType: " . $node->nodeType . "\n";
|
|
|
|
?>
|
|
--EXPECT--
|
|
root
|
|
nodeType: 1
|
|
child
|
|
nodeType: 1
|