Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81485 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23912 invoked from network); 31 Jan 2015 13:18:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2015 13:18:15 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:58100] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 62/21-16633-416DCC45 for ; Sat, 31 Jan 2015 08:18:14 -0500 Received: by mail-wi0-f173.google.com with SMTP id r20so8268373wiv.0 for ; Sat, 31 Jan 2015 05:18:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=BBnGKDzd4ZA/i7WeDIrQ3MbYex6ByOhIw2GmWF4Eohg=; b=WqHWS7Fgnz8I3fIp6tvCDml3BfSyJk7nZ81K7M5DJMhTyLPCCpZGzZ9pCdsOtfrx/l yGvCXAtOlMRSGTIErTVf0e/BAzub03dQS2dnsYcrrienOxJ4HA8HRM0gDid8WLcBopdE /G13ehjbon0RCiW4GP0JWmF78VmZi7wvrvQj+7f5N5OxKR5Ae/alpLfhlCqrt6VIa2Q1 QygiqEQoXl/edUM1u4mE6hELvtVTGPoFbYLigVzfB4+x21qzdNRj12hSJ81R5zGPl+Rj bKNkOaFzGCccnjgvMjsmGUpH/Z680bmlkOXtbpcMMQWavwb/NYF9Sq1nRdmqHC99sH7M cqjA== MIME-Version: 1.0 X-Received: by 10.180.207.83 with SMTP id lu19mr4677558wic.52.1422710288173; Sat, 31 Jan 2015 05:18:08 -0800 (PST) Received: by 10.27.10.138 with HTTP; Sat, 31 Jan 2015 05:18:08 -0800 (PST) In-Reply-To: References: Date: Sat, 31 Jan 2015 14:18:08 +0100 Message-ID: To: Dmitry Stogov Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c3a6b858681c050df28d86 Subject: Re: [PHP-DEV] [RFC] Fix "foreach" behavior From: nikita.ppv@gmail.com (Nikita Popov) --001a11c3a6b858681c050df28d86 Content-Type: text/plain; charset=UTF-8 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 --001a11c3a6b858681c050df28d86--