Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81422 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26634 invoked from network); 30 Jan 2015 11:07:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2015 11:07:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=permerror Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 78.32.209.33 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 78.32.209.33 freshmint.phcomp.co.uk Received: from [78.32.209.33] ([78.32.209.33:57690] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5E/A0-23158-7E56BC45 for ; Fri, 30 Jan 2015 06:07:20 -0500 Received: from addw by mint.phcomp.co.uk with local (Exim 4.72) (envelope-from ) id 1YH9Pw-0004rH-O1 for internals@lists.php.net; Fri, 30 Jan 2015 11:07:16 +0000 Date: Fri, 30 Jan 2015 11:07:16 +0000 To: internals@lists.php.net Message-ID: <20150130110716.GA18357@phcomp.co.uk> Mail-Followup-To: internals@lists.php.net References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Parliament Hill Computers Ltd User-Agent: Mutt/1.5.20 (2009-12-10) Subject: Re: [PHP-DEV] [RFC] Fix "foreach" behavior From: addw@phcomp.co.uk (Alain Williams) On Fri, Jan 30, 2015 at 11:23:19AM +0400, Dmitry Stogov wrote: > Hi, > > I'd like to start discussion about fixing inconsistent "foreach" statement > behavior. > The implementation is almost done. It not only fixes inconsistencies in a > defined by RFC way but also improves performance in most usual cases, > because now foreach by value over array doesn't require array duplication. > > https://wiki.php.net/rfc/php7_foreach > > https://github.com/php/php-src/pull/1034 > > I'm going to continue work on implementation improvement and may be fixing > related behavior of some internal functions when they used on array > iterated by foreach by reference (e.g. array_unshift()). However, the > conceptual behavior defined in RFC is not going to be changed anymore. I think that I am raising a concern that is not real, but I'll do so anyway. You write: This will lead to copy-on-write on attempt of array modification inside the loop. As result, we will always iterate over elements of array originally passed to foreach, ignoring any possible array changes. I think that you mean modification of the array and that this does not relate to modification of array elements. Ie will code like the following still work: foreach($_POST as &$v) $v = trim($v); Otherwise - good. -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include