Re: foreach, assigning to a reference, and E_NOTICE
| From: | Xuefer | Date: | Tue, 07 Mar 2006 06:09:31 +0000 |
| Subject: | Re: foreach, assigning to a reference, and E_NOTICE | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-22165@lists.php.net to get a copy of this message | ||
> Sean's not so much referring to his own problem as (like you said) the
> solution is a fairly simple matter of following strict coding practices.
yeah, i see.
but...
> when foreach assigns to a pre-existing
> reference target
it's not the problem of the second foreach, any usage of $j after the
1st foreach as &$j will hurt
<?php
$i = array('zero','one','two');
foreach ($i as &$j) { do something here }
for ($j = 0; $j < 10; $j ++) {
..
}
$i[2] is modified
?>
iirc, there was a discussion about foreach behavior(leave assigned
key/value variable not unset after foreach) last year already.
i'd like to see it solved too, but with a real fix.