Re: foreach weirdness
| From: | Simon Schick | Date: | Sun, 25 Mar 2012 21:55:20 +0000 |
| Subject: | Re: foreach weirdness | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317261@lists.php.net to get a copy of this message | ||
2012/3/25 Arno Kuhl <arno@dotcontent.net>:
>
> will not only give the wrong result, it will corrupt the array for *any* further use of that
> array. I still think it’s a bug according to the definition of foreach in the php manual. Maybe
> php needs to do an implicit unset at the closing brace of the foreach where was an assign $value by
> reference, to remove the reference to the last element (or whatever element it was pointing to if
> there was a break) so that it doesn't corrupt the array, because any assign to $value after the
> foreach loop is completed will corrupt the array (confirmed by testing). The average user (like me)
> wouldn't think twice about reusing $value after ending the foreach loop, not realising that
> without an unset the array will be corrupted.
>
Hi, Arno
Requesting that will at least require a major-release (f.e. PHP 6.0)
... but I would rather request to add a notice or warning to the
documentation of references to remind stuff like that.
http://www.php.net/manual/en/language.references.php
I think this is stuff more people will stumble over ...
Bye
Simon