DOMNode children iteration (was Re: array() returns something weird)
| From: | Martin Scotta | Date: | Tue, 25 Aug 2009 21:25:06 +0000 |
| Subject: | DOMNode children iteration (was Re: array() returns something weird) | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297227@lists.php.net to get a copy of this message | ||
---------- Forwarded message ----------
From: Martin Scotta <martinscotta@gmail.com>
Date: Tue, Aug 25, 2009 at 6:24 PM
Subject: Re: [PHP] DOMNode children iteration (was Re: array() returns
something weird)
To: webmaster@strefarytmu.pl
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@strefarytmu.pl>
>
> 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