Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19048 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80457 invoked by uid 1010); 16 Sep 2005 12:30:03 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 80442 invoked from network); 16 Sep 2005 12:30:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Sep 2005 12:30:03 -0000 X-Host-Fingerprint: 195.225.34.5 fw01.axit.nl Received: from ([195.225.34.5:9151] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 67/0C-43379-BCABA234 for ; Fri, 16 Sep 2005 08:30:03 -0400 Message-ID: <67.0C.43379.BCABA234@pb1.pair.com> To: internals@lists.php.net Date: Fri, 16 Sep 2005 14:29:58 +0200 Lines: 77 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: big reference bug in (at least) PHP 5.0.5 From: r.korving@xit.nl ("Ron Korving") 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: $i); foreach ($array as &$item) $item["bar"] = $item["foo"] * 2; print_r($array); foreach ($array as $item) print_r($item); ?> The expected result would be to see whatever is in the array twice. Once in the big print_r() on $array, and once per element of $array. Here's the actual result (look at the last array element): Array ( [0] => Array ( [foo] => 0 [bar] => 0 ) [1] => Array ( [foo] => 1 [bar] => 2 ) [2] => Array ( [foo] => 2 [bar] => 4 ) ) Array ( [foo] => 0 [bar] => 0 ) Array ( [foo] => 1 [bar] => 2 ) Array ( [foo] => 1 [bar] => 2 ) So referencing wih foreach() is obviously buggy. With this foreach it works just fine: foreach ($array as $i => $item) $array[$i]["bar"] = $item["foo"] * 2; I fear this bug is not just present in PHP 5.0.5, but in older versions too. Ron Korving