DOMNode children iteration (was Re: array() returns something weird)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





---------- Forwarded message ----------
From: Martin Scotta <martinscotta@xxxxxxxxx>
Date: Tue, Aug 25, 2009 at 6:24 PM
Subject: Re: DOMNode children iteration (was Re: array() returns something weird)
To: webmaster@xxxxxxxxxxxxxx


Fatal error: Call to a member function getAttribute() on a non-object in testme.php on line 121

I'm using a Apache/2.2.3 (Win32) PHP/5.2.6
Is the script correctly? I have removed the "&" in the loop and the script returns the attached file.

It looks like a bogus bug?

2009/8/24 Szczepan Hołyszewski <webmaster@xxxxxxxxxxxxxx>

Hi Lars and list!

New facts about the strange bug initially diagnosed as array() returning NULL:

Firstly, the issue is not really about array() returning null, but about full
blown UndefinedBehavior(TM) progressively trashing local variables. It just so
happened that I noticed it first with a variable to which array() had been
assigned just before things began breaking.

Secondly, I proudly present the culprit: things break when I iterate over a
DOMNode's children *by reference* using firstChild and nextSibling:

       for($child=&$node->firstChild; $child; $child=&$child->nextSibling) {

               //processing...
       }

No problems if iteration is done by value or by DOMNodeList (childNodes,
DOMXPath...).

HOWEVER,

I still consider this a bug because it destablizes PHP. After the evil loop
has finished, things happen that should never happen, like a variable being
NULL immediately after being assigned array().

I attach a demonstration. It is a self-contained commented script that you can
execute from command line. Also attached is output on my machine.

Best regards,
Szczepan Hołyszewski

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
Martin Scotta



--
Martin Scotta
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux