From:             benoit dot toutain at free dot fr
Operating system: Linux 2.6.3-4mdk
PHP version:      5.0.0RC3
PHP Bug Type:     DOM XML related
Bug description:  DOMNodeList->item works strangely

Description:
------------
the item function of DOMNodeList class seems to not work correctly. It
retreives only the first half part of NodeList members.

Reproduce code:
---------------
$doc = new DOMDocument;
        $nodeRoot = $doc->appendChild(new DOMElement("root"));
        for ( $i = 1; $i <= 10; $i++ )
        {
                $newNode = $doc->importNode(new DOMElement("child"));
                $newNode = $nodeRoot->appendChild($newNode);
                $newNode->setAttribute("id",$i);
        }
        
        echo htmlentities($doc->saveXML());
        
        $nodeList = $nodeRoot->childNodes;
        $nbChildNodes = $nodeList->length;
        echo "<br/>nbchildnodes = $nbChildNodes</br>\n";
        for ($i = 0; $i < $nbChildNodes; $i++)
        {
                echo "i = $i<br/>\n";
                $node = $nodeList->item($i);
                $nodeRoot->removeChild($node);
        }
        
        echo "<br/><br/>\n";
        echo htmlentities($doc->saveXML());

Expected result:
----------------
<?xml version="1.0"?> <root><child id="1"/><child id="2"/><child
id="3"/><child id="4"/><child id="5"/><child id="6"/><child id="7"/><child
id="8"/><child id="9"/><child id="10"/></root>
nbchildnodes = 10
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9

<?xml version="1.0"?> <root/>

Actual result:
--------------
<?xml version="1.0"?> <root><child id="1"/><child id="2"/><child
id="3"/><child id="4"/><child id="5"/><child id="6"/><child id="7"/><child
id="8"/><child id="9"/><child id="10"/></root>
nbchildnodes = 10
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5

Warning: removeChild() expects parameter 1 to be DOMNode, null given in
/home/apache/htdocs/test_dom/test.php on line 27
i = 6

Warning: removeChild() expects parameter 1 to be DOMNode, null given in
/home/apache/htdocs/test_dom/test.php on line 27
i = 7

Warning: removeChild() expects parameter 1 to be DOMNode, null given in
/home/apache/htdocs/test_dom/test.php on line 27
i = 8

Warning: removeChild() expects parameter 1 to be DOMNode, null given in
/home/apache/htdocs/test_dom/test.php on line 27
i = 9

Warning: removeChild() expects parameter 1 to be DOMNode, null given in
/home/apache/htdocs/test_dom/test.php on line 27


<?xml version="1.0"?> <root><child id="2"/><child id="4"/><child
id="6"/><child id="8"/><child id="10"/></root>

-- 
Edit bug report at http://bugs.php.net/?id=28797&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28797&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28797&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28797&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28797&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28797&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28797&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28797&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28797&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28797&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28797&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28797&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28797&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28797&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28797&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28797&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28797&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28797&r=float

Reply via email to