From: olaf at 7val dot com Operating system: Linux PHP version: 5.1.2 PHP Bug Type: Scripting Engine problem Bug description: DOMDocument::removeChild corrupts node
Description: ------------ Using DOMDocument::removeChild corrupts node in the document in some cases. Given a node $node and removing a parent node of this node renders $node unusable (properties are gone, but $node is still of class DOMElement). Reproduce code: --------------- <?php // This works as expected $dom = DOMDocument::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"; echo "nodeName: " .$node->nodeName . "\n"; echo "parentNode: " .$node->parentNode . "\n"; // This breaks "$node" $dom = DOMDocument::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"; echo "nodeName: " .$node->nodeName . "\n"; echo "parentNode: " .$node->parentNode . "\n"; echo "\n"; ?> Expected result: ---------------- Properties of $node should still exists, see part1: root nodeType: 1 nodeName: root parentNode: Actual result: -------------- Properties are gone child Notice: Undefined property: DOMElement::$nodeType in /home/olaf/test/test.php on line 20 nodeType: Notice: Undefined property: DOMElement::$nodeName in /home/olaf/test/test.php on line 21 nodeName: Notice: Undefined property: DOMElement::$parentNode in /home/olaf/test/test.php on line 22 parentNode: -- Edit bug report at http://bugs.php.net/?id=36756&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36756&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36756&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36756&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36756&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36756&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36756&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36756&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36756&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36756&r=support Expected behavior: http://bugs.php.net/fix.php?id=36756&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36756&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36756&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36756&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36756&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36756&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36756&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36756&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36756&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36756&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36756&r=mysqlcfg