Re: Re: Possible foreach bug; seeking advice to isolate the problem

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

 



On 23 October 2010 07:50, Jonathan Sachs <081012@xxxxxxxxxxx> wrote:
> Gary wrote:
>
>>Better. I can tell you how to solve it:
>> Â Â$a = array('a', 'b','c');
>> Â Âforeach($a as &$row){
>> Â Â Â Â//you don't have to do anything here
>> Â Â}
>> Â Âunset($row); // <----<<< THIS IS KEY!
>> Â Âprint_r($a);
>> Â Âforeach($a as $row){
>> Â Â Â Âecho "<br />".$row;
>> Â Â}
>> Â Âprint_r($a);
>
> I see what you're doing now: unsetting the variable, not the array
> element referenced by the variable. You're right, it does work.
>
> It's not exactly better than knowing what's wrong, though... it's
> different. I already had a workaround, although it was not quite as
> elegant. My desire now is to find out whether the behavior I described
> is due to something I don't understand about PHP, or to a bug. If it's
> something I don't understand, I want to understand it. If it's a bug,
> I want to report it.

It is not a bug - somewhere before the foreach loop you've got, a
variable is being referenced, and that's throwing things off.
Otherwise, unsetting the variable would have no effect on the problem
you're seeing.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

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