]> granicus.if.org Git - php/commitdiff
MFB51: Fixed bug #36756 (DOMDocument::removeChild corrupts node)
authorRob Richards <rrichards@php.net>
Sat, 18 Mar 2006 11:46:13 +0000 (11:46 +0000)
committerRob Richards <rrichards@php.net>
Sat, 18 Mar 2006 11:46:13 +0000 (11:46 +0000)
add test

ext/dom/php_dom.c
ext/dom/tests/bug36756.phpt [new file with mode: 0644]

index 925b230fc016e20c6b89f6dab152a228d79acfdf..a75cdfab856da092d90bfbd5631b3907070d00ab 100644 (file)
@@ -306,6 +306,8 @@ zval *dom_read_property(zval *object, zval *member, int type TSRMLS_DC)
 
        if (obj->prop_handler != NULL) {
                ret = zend_u_hash_find(obj->prop_handler, Z_TYPE_P(member), Z_UNIVAL_P(member), Z_UNILEN_P(member)+1, (void **) &hnd);
+       } else if (instanceof_function(obj->std.ce, dom_node_class_entry TSRMLS_CC)) {
+               php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", obj->std.ce->name);
        }
        if (ret == SUCCESS) {
                ret = hnd->read_func(obj, &retval TSRMLS_CC);
diff --git a/ext/dom/tests/bug36756.phpt b/ext/dom/tests/bug36756.phpt
new file mode 100644 (file)
index 0000000..e24f9f0
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Bug #36756: (DOMDocument::removeChild corrupts node)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--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";
+
+?>
+--EXPECTF--
+root
+nodeType: 1
+child
+
+Warning: Couldn't fetch DOMElement. Node no longer exists in %sbug36756.php on line %d
+
+Notice: Undefined property:  DOMElement::$nodeType in %sbug36756.php on line %d
+nodeType: