php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17771 insert_before misbeaviour (DOM L2 spec.)
Submitted: 2002-06-15 08:08 UTC Modified: 2002-08-14 12:12 UTC
From: rui at ruilopes dot com Assigned:
Status: Closed Package: DOM XML related
PHP Version: 4.2.1 OS: Win2k
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rui at ruilopes dot com
New email:
PHP Version: OS:

 

 [2002-06-15 08:08 UTC] rui at ruilopes dot com
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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-14 12:12 UTC] chregu@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 19:01:32 2024 UTC