Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81519 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35209 invoked from network); 1 Feb 2015 03:39:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2015 03:39:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; 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:48852] helo=mail-vc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/0E-01632-8FF9DC45 for ; Sat, 31 Jan 2015 22:39:37 -0500 Received: by mail-vc0-f177.google.com with SMTP id hy4so12933124vcb.8 for ; Sat, 31 Jan 2015 19:39:34 -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:cc:content-type; bh=oOYiSy9XrIRjxyGds/BLYSIf5mwZGyYZTCLP25NJwwk=; b=dEZHB2I/WzFqco8JFIdtLlx8IVFZnt+xfI2Vs9v74JRh/A17Kq+/GKjhctvHLiDUpR VUeqWHb43uEa9/UHxducF8y9a8WEzAZ+2tzbAxo0IkJ2FXgOsRuP5lImebPGqhj0yfeI +ARCsOh8ZD9EV8afczQbmPbgYJu+Lb3vxdyJypn89ttipjuAfwrsHl+I1piov+++tJZb MCpUr5otiw20uYTA332Ge7u/JYL0pa+LuHpOvC9AmvxALQZA8Ke+mWVkH82w8QvLHzXY FihEnabiaX0cjjNr7IakYkkggS0Giy8e1Q3FILWygcq/TjYHQbiOB/uZZTo4ccO+jhm3 e8lg== X-Gm-Message-State: ALoCoQnRrm/v0vkHu/DlHsdv42h1WovzLh42RJdSlCYov3r22U0CB8lVm3mI1GaDjZJSV/rLmc+LoYdQZYQj7paY8PXJPy5WXTClIEVhZVG/mYffQSc6ypSTAHO4drebC5seGVOFgjTADj2oH3StXPa/au+x6GIpuQ== MIME-Version: 1.0 X-Received: by 10.220.185.193 with SMTP id cp1mr7831348vcb.80.1422761974521; Sat, 31 Jan 2015 19:39:34 -0800 (PST) Received: by 10.52.26.40 with HTTP; Sat, 31 Jan 2015 19:39:34 -0800 (PST) Received: by 10.52.26.40 with HTTP; Sat, 31 Jan 2015 19:39:34 -0800 (PST) In-Reply-To: References: Date: Sun, 1 Feb 2015 07:39:34 +0400 Message-ID: To: Nikita Popov Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e01538610177b94050dfe9646 Subject: Re: [PHP-DEV] [RFC] Fix "foreach" behavior From: dmitry@zend.com (Dmitry Stogov) --089e01538610177b94050dfe9646 Content-Type: text/plain; charset=UTF-8 I also thought about similar approach for "object by value case". I think, first we should accept the proposed in thic RFC behavior. It's consistent, and more comatible with PHP5. Later, if we decide to merge zend_array with HashTable we may try to change it. Thanks. Dmitry. On Jan 31, 2015 4:18 PM, "Nikita Popov" wrote: > On Fri, Jan 30, 2015 at 8:23 AM, 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. >> >> Thanks. Dmitry. >> > > I think the new behavior introduced by this RFC is much more consistent > than what we have right now. Previously things depended on details of > refcounting and hashing and had very weird interaction with current() etc. > Now the behavior looks clear for all cases. > > There's just one thing I'd like to discuss: The object by-value case: > > Currently this is handled in much the same way as array by-reference, i.e. > changes to the object will influence iteration. Currently we can't > implement this any differently, however if we always use zend_array instead > of HashTable (and fully support refcounting for this), as has been > suggested in another thread, we could handle this case the same way as > arrays (i.e. just add a refcount to the properties zend_array). Assuming we > can implement it this way, I'm not totally sure which behavior makes more > sense. On one hand it would make arrays and plain objects work the same > way. On the other hand arrays and objects have different copying semantics > in other places as well. > > Anyway, big +1 on this, thanks for implementing it. > > Nikita > --089e01538610177b94050dfe9646--