note 65969 deleted from function.dom-domdocument-getelementsbytagname by didou
| From: | didou@php.net | Date: | Sat, 30 Dec 2006 03:14:10 +0000 |
| Subject: | note 65969 deleted from function.dom-domdocument-getelementsbytagname by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121048@lists.php.net to get a copy of this message | ||
Note Submitter: captainbajoo at juno dot com
----
(As of v5.0.5, Win32)
Altering the document structure while iterating the NodeList returned by getElementsByTagName()
affects the NodeList you are iterating. Combined with the DOMNode->insertBefore() method, this is
a good way to create an infinite loop!
Example:
<?php
$dom = new DOMDocument();
$rootNode = $dom->createElement('root');
$dom->appendChild($rootNode);
$firstNode = $dom->createElement('first');
$rootNode->appendChild($firstNode);
$allnodes = $dom->getElementsByTagName('*');
foreach ($allnodes as $node) {
$newNode = $dom->createElement('infinite');
$node->parentNode->insertBefore($newNode, $node);
}
# the loop never terminates; on the next iteration, $node <= $newNode, another
'infinite' node is created and inserted before it, and so on
?>