Bug #17771: insert_before misbeaviour (DOM L2 spec.)
| From: | rui at ruilopes dot com | Date: | Sat, 15 Jun 2002 12:08:34 +0000 |
| Subject: | Bug #17771: insert_before misbeaviour (DOM L2 spec.) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-10494@lists.php.net to get a copy of this message | ||
From: rui@ruilopes.com
Operating system: Win2k
PHP version: 4.2.1
PHP Bug Type: DOM XML related
Bug description: insert_before misbeaviour (DOM L2 spec.)
An excerpt from DOM Level 2 Node::insertBefore:
"If the newChild is already in the tree, it is first removed."
In php 4.2.1 newChild is not removed from tree, it is only copied to the
new location.
Here is some sample code,
$xml = <<<EOD
<root>
<Test>
data to merge in parent
bla bla
<node>asdasd</node>
</Test>
<Treta>
contents
</Treta>
</root>
EOD;
/* Move all children nodes to parent node of $fromNode. */ function
MoveChildrenToParent($fromNode) {
$parentNode = $fromNode->parent_node();
foreach ($fromNode->child_nodes() as $childNode) {
//$fromNode->remove_child($childNode); // <-- uncomment this
$parentNode->insert_before($childNode, $fromNode);
}
}
$dom = domxml_open_mem($xml);
$root = $dom->document_element();
$children = $root->child_nodes();
$testNode = $children[1];
MoveChildrenToParent($testNode);
As you can see the children of Test node were not moved to root, they were
copied. (uncomment the remove_child call from MoveChildrenToParent to see
the right behavior)
--
Edit bug report at http://bugs.php.net/?id=17771&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=17771&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=17771&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=17771&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=17771&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17771&r=support
Expected behavior: http://bugs.php.net/fix.php?id=17771&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17771&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17771&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=17771&r=globals