Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81423 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28831 invoked from network); 30 Jan 2015 11:28:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2015 11:28:04 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.177 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.177 mail-vc0-f177.google.com Received: from [209.85.220.177] ([209.85.220.177:41641] helo=mail-vc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AB/01-23158-3CA6BC45 for ; Fri, 30 Jan 2015 06:28:04 -0500 Received: by mail-vc0-f177.google.com with SMTP id hy4so10565968vcb.8 for ; Fri, 30 Jan 2015 03:28:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=QixucIzL9JAPUs54t/l7ORAhDJ7/Z3sHlVR35HiWxpU=; b=X60hLkzCjtpS6EyKzvLqFN1h/1y98u3LQFLrrGb4G88/5DF6uYdmKhSSlIlD/kxcPG eOD1YwljSBUz8RPtQPrY1C/TutQeZeepgSP3dfN6mkN94pl/A8qN2hHz30j35DGaQMQf PU8OBL9azy9g23bcPG9gBM/OrGAAzI5JpRB/u8KSe78XGlNs+tyh7aXcherp/A5OwsoT UqVH4zwaNTJYLWmU55bH/6LcITKyCU3C/jtFjMWvzEmi6KrCPgVKkoPNWZZDzMOLBHHI MaenRRQ7ke9eEhUZ8LbgL6kYrsHiQlJV4d1gzIfOARbe/tPjsDYSMZNDygOMdhwibrnB sz8A== X-Gm-Message-State: ALoCoQnBTYPKxRGPHk024SeN295m2bFGtv0u5zx7p1Lu5MhGIZDby6xOj6a8W0Csxa9+xX2mlhYb/ZwL0fHn01XqCc5hMukWrMqUyjxj4CWTStpsPbFLDnoGVhEybt8WEP6E2JUhGGFbPbSQ9EsTMsdA56lf9rfwLQ== MIME-Version: 1.0 X-Received: by 10.52.26.110 with SMTP id k14mr2364854vdg.65.1422617281260; Fri, 30 Jan 2015 03:28:01 -0800 (PST) Received: by 10.52.26.40 with HTTP; Fri, 30 Jan 2015 03:28:01 -0800 (PST) In-Reply-To: <20150130110716.GA18357@phcomp.co.uk> References: <20150130110716.GA18357@phcomp.co.uk> Date: Fri, 30 Jan 2015 15:28:01 +0400 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=20cf307d0482b38630050ddce514 Subject: Re: [PHP-DEV] [RFC] Fix "foreach" behavior From: dmitry@zend.com (Dmitry Stogov) --20cf307d0482b38630050ddce514 Content-Type: text/plain; charset=UTF-8 That sentence was about "foreach by value". "foreach by reference" in your example will still work as expected :) Thanks. Dmitry. On Fri, Jan 30, 2015 at 2:07 PM, Alain Williams wrote: > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf307d0482b38630050ddce514--