php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31484 Strage behaviour when looping through a NodeList
Submitted: 2005-01-11 01:30 UTC Modified: 2005-01-11 09:18 UTC
From: clynx at users dot sourceforge dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.0.3 OS: FreeBSD 4.11
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: clynx at users dot sourceforge dot net
New email:
PHP Version: OS:

 

 [2005-01-11 01:30 UTC] clynx at users dot sourceforge dot net
Description:
------------
I want to use a complete Namespace to execute self written PHP Classes.
My Parser has some Problems with the way PHP handles the Code.

It seems like my code handles all dom Functions right, but the Result is not the one I would expect.

Reproduce code:
---------------
<?php
$dom = new DOMDocument();
$dom->load("http://www.succont.de/php/domxml.xml");

$nodelist=$dom->getElementsByTagNameNS( 'http://test.de/test', '*' );
for($i = 0; $i < $nodelist->length; $i++)
{
    $node = $nodelist->item($i);
    if($node->localName == "test")
    {
         $node->parentNode->removeChild($node);
         echo $node->localName . " removed \n";
     } else {
         echo 'handle: ' . $node->localName . "\n";
     }
}
echo "\nXML File:\n".$dom->saveXML();
?>

Expected result:
----------------
bash-2.05a$ php -q test.php
handle: doSomething
test removed
handle: doSomething

XML File:
<?xml version="1.0" encoding="utf-8"?>
<example xmlns:test="http://test.de/test">
        <test:doSomething/>

        <test:doSomething/>
</example>

Actual result:
--------------
bash-2.05a$ php -q test.php
handle: doSomething
test removed

XML File:
<?xml version="1.0" encoding="utf-8"?>
<example xmlns:test="http://test.de/test">
        <test:doSomething/>

        <test:doSomething/>
</example>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-11 01:56 UTC] clynx at users dot sourceforge dot net
updated libxml2 to 2.6.16, same error
 [2005-01-11 08:19 UTC] chregu@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

A nodelist is a so called "live" collection. Meaning, if you remove an element from it, nodelist->length will be one less. This should explain your behaviour.


 [2005-01-11 09:18 UTC] clynx at users dot sourceforge dot net
Tried to get Support, but most of them did not know new dom, or thought the behaviour should be as i expected.

Thank you for your answer, and sorry for buging. ;o)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 07:01:27 2024 UTC