note 72271 added to function.dom-domnodelist-item
| From: | tfg_allardyce at gmail dot com | Date: | Wed, 10 Jan 2007 11:57:15 +0000 |
| Subject: | note 72271 added to function.dom-domnodelist-item | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121524@lists.php.net to get a copy of this message | ||
Be careful when looping through a DOMNodeList and moving its nodes around, sometimes this will take
that node off the DOMNodeList and sometimes it wont!
<?php
// let $nodes be node list and $parent be some other node
foreach($nodes as $node) {
$parent->appendChild($node);
}
?>
In some cases the $node will be taken off the list and the next iteration of the loop will be
corrupted, skipping every other node in the list! In other cases the node will remain in the list
and everything will be fine.
Generally if you've created the node list using a getElementsByTagName call or an XPath query
then the nodes will stay on the list. If the node list comes from another nodes' childNodes
property those child nodes will be shifted off the list whenever you call appendChild.
----
Server IP: 66.163.161.117
Probable Submitter: 80.47.73.23
----
Manual Page -- http://www.php.net/manual/en/function.dom-domnodelist-item.php
Edit -- https://master.php.net/note/edit/72271
Del: integrated -- https://master.php.net/note/delete/72271/integrated
Del: useless -- https://master.php.net/note/delete/72271/useless
Del: bad code -- https://master.php.net/note/delete/72271/bad+code
Del: spam -- https://master.php.net/note/delete/72271/spam
Del: non-english -- https://master.php.net/note/delete/72271/non-english
Del: in docs -- https://master.php.net/note/delete/72271/in+docs
Del: other reasons-- https://master.php.net/note/delete/72271
Reject -- https://master.php.net/note/reject/72271
Search -- https://master.php.net/manage/user-notes.php