"Rasmus Lerdorf" <ras...@lerdorf.com> wrote in message 
news:4b3785ac.2000...@lerdorf.com...
> We can't just randomly reset variables based on their scope in this one
> specific case.  If we are going to "fix" this, it should be done by
> introducing a way to do proper local scope variables.  Resetting a
> reference simply because it is convenient in this one case would be
> completely inconsistent.
>
> -Rasmus

Rasmus,
it's not required to do anything like that and I myself would be against any 
random resets,
but it's definitely not the case. There is nothing random and everything is 
well determinted.
As I see the problem, it would be sufficient to fix the FOREACH and make it 
working in the following way:
For example, say we have $a=array('apple', 'orange');
and iterate through $a values:
foreach($a as &$v) ...
as an initial step, $v MUST be assigned to the very first element of $a 
which 'apple'. It should be done regadless of the
value that might be assigned  to $v before (that's the first change)
On the next step, it will be advanced by one and assign $v to point to 
'orange'
On the next iteration, it MUST also be advanced by one, reach the End Of the 
Array, so it should assign NULL (or FALSE?) value to $v,
then finish the loop.

Isn't it what would work in a clearer way?

Evenmore, this change would make the foreach working more consistent with 
each()/next()/prev() - they return FALSE as soon as internal pointer
reaches either boundary of the array. Neither stick with last element, like 
foreach().

If you think current behaviour of foreach is useful, it's possible to 
introduce new setting in php.ini, say strict_foreach=ON that will break
BC, but make foreach working clearer.

-jv




-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to