Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22141 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63182 invoked by uid 1010); 6 Mar 2006 18:16:30 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 63167 invoked from network); 6 Mar 2006 18:16:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Mar 2006 18:16:30 -0000 X-Host-Fingerprint: 69.60.120.90 iconoclast.caedmon.net Linux 2.4/2.6 Received: from ([69.60.120.90:40368] helo=iconoclast.caedmon.net) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 1D/4C-22029-E7C7C044 for ; Mon, 06 Mar 2006 13:16:30 -0500 Received: from localhost ([127.0.0.1]) by iconoclast.caedmon.net with esmtp (Exim 3.35 #1 (Debian)) id 1FGKEf-0004C1-00 for ; Mon, 06 Mar 2006 13:15:09 -0500 Message-ID: <440C7D6F.7030809@caedmon.net> Date: Mon, 06 Mar 2006 13:20:31 -0500 User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: foreach, assigning to a reference, and E_NOTICE From: sean@caedmon.net (Sean Coates) Hi, A week or two ago, a colleague asked me about a strange behaviour he experienced, with seemingly-duplicate data within a foreach block. Upon further examination, we determined that this was caused by assigning to a referenced variable: (Output is: "zero one one") I asked around about this, and was given the technical explanation (see http://sean.caedmon.net/notsoweird.phps if you're curious), which cleared it up. However, upon further discussion, a number of us agreed that it would be pertinent to raise an E_NOTICE when foreach assigns to a pre-existing reference target. Certainly, the behaviour demonstrated above is non-obvious, and contrary to the normal "PHP way" (simplicity). Developers, at least in my opinion, don't expect foreach to WRITE to the iterated array. Technical explanation aside (yes, we realize that this is "normal" behaviour, as demonstrated in the unroll), I believe this represents a usability problem. Can we throw an E_NOTICE when foreach targets a reference? (The other option we kicked around was implicitly unset()ing the target variable before the first iteration, but this was deemed "too magical".) If so, when? HEAD only? I'd like to see it in 5.2 as well, if that ever exists, but I agree that it's too late for 5.1. S