Re: foreach weirdness

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

 



2012/3/25 Arno Kuhl <arno@xxxxxxxxxxxxxx>:
>
> 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

-- 
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