Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19051 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98200 invoked by uid 1010); 16 Sep 2005 12:53:54 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 98185 invoked from network); 16 Sep 2005 12:53:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Sep 2005 12:53:54 -0000 X-Host-Fingerprint: 195.225.34.5 fw01.axit.nl Received: from ([195.225.34.5:28622] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 96/CE-43379-260CA234 for ; Fri, 16 Sep 2005 08:53:54 -0400 Message-ID: <96.CE.43379.260CA234@pb1.pair.com> To: internals@lists.php.net References: <67.0C.43379.BCABA234@pb1.pair.com> <432ABD29.6000605@zend.com> Date: Fri, 16 Sep 2005 14:53:51 +0200 Lines: 79 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Posted-By: 195.225.34.5 Subject: Re: [PHP-DEV] big reference bug in (at least) PHP 5.0.5 From: r.korving@xit.nl ("Ron Korving") Okay, you're right that it starts working fine when I rename the $item to $blah, but your explanation doesn't make much sense. After the first foreach, $item points to the last one, that I already figured. If you ask me, the second foreach should replace the instance of $item, not overwrite it. But it doesn't seem to overwrite it, because if you look at the results, the last element is replaced by the contents of the one before the last element. If you do these loops with $i < 10, you will see it more clearly maybe. The last item in the array is replaced, not by the first one of the second foreach, but by the item before the last item. That just doesn't make sense at all. And really, I do consider foreach() overwriting previous references a bug. If it wasn't, then this: $i=0; foreach ($array as &$foo) $foo = $i++; should have the last value on every item, because within this foreach() the $foo's should overwrite eachother with your logic. Ron "Antony Dovgal" schreef in bericht news:432ABD29.6000605@zend.com... > On 16.09.2005 16:29, Ron Korving wrote: > > My apologies for my DOM-mistake today, but right now I came across something > > that totally stunned me. It's a total paradox situation that just has to be > > one of the biggest bugs I've ever come across in PHP. Personally, I think > > it's rather high-priority because it's an engine problem, and not an issue > > with some extension. > > > > Here's the code: > > > > > $array = array(); > > > > for ($i=0; $i < 3; $i++) > > $array[] = array("foo" => $i); > > > > foreach ($array as &$item) > > $item["bar"] = $item["foo"] * 2; > > > > print_r($array); > > > > foreach ($array as $item) > > print_r($item); > > ?> > > Ron, after the first foreach $item still points to the last element of $array (because you've used &$item syntax). > The second foreach changes $item, but it *STILL* references the last element of $array, so it actually changes it instead. > > Try to change this part of the code: > foreach ($array as $item) > print_r($item); > > to: > foreach ($array as $blah) > print_r($blah); > > you'll see it yourself. > > I don't see any bugs here. > > -- > Wbr, > Antony Dovgal