> However, upon further discussion, a number of us agreed that it would be
> pertinent to raise an E_NOTICE when foreach assigns to a pre-existing
> reference target. Certainly, the behaviour demonstrated above is
> non-obvious, and contrary to the normal "PHP way" (simplicity).
> Developers, at least in my opinion, don't expect foreach to WRITE to the
> iterated array.
>
> Technical explanation aside (yes, we realize that this is "normal"
> behaviour, as demonstrated in the unroll), I believe this represents a
> usability problem.
>
> Can we throw an E_NOTICE when foreach targets a reference? (The other
there's many way to use reference, not only in foreach. don't do
reference unless u know it's really needed.
> option we kicked around was implicitly unset()ing the target variable
> before the first iteration, but this was deemed "too magical".)
>
> If so, when? HEAD only? I'd like to see it in 5.2 as well, if that ever
> exists, but I agree that it's too late for 5.1.
due to php's auto gc, no one unset variable after using it.
but one of my "good design rule" is:
always unset the _referenced_ variable immediately after it's used,
this helps a lot, and is almost important as escape the string before
sql query. no?
>
> S
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to