Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96643 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7211 invoked from network); 30 Oct 2016 11:24:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Oct 2016 11:24:50 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.213.48 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.213.48 mail-vk0-f48.google.com Received: from [209.85.213.48] ([209.85.213.48:34403] helo=mail-vk0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/0F-25911-E78D5185 for ; Sun, 30 Oct 2016 06:24:47 -0500 Received: by mail-vk0-f48.google.com with SMTP id x186so27460173vkd.1 for ; Sun, 30 Oct 2016 04:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ZxW1kNoNYq+nIRbKxQ+OJuPZZtbedkQq6ghCw0HhbMA=; b=I+LSbKaWWR9Va6/WJqYEwdGsFJwkO4uhLSXVxafTTqDr+epsLshay3stpx39Qm+m4A IDakdTs3Y1n4dywd9RIIUpIVcAEeqJGSjwlUNRTR6LcB3I9XRcZFsrWXLmPkp0yO2C1b 4YL+F5DMQjUQ+ELeX9iJ1ojaxFOca7exQ0Rlz3BgP/4rSto9rXnOIpIb3AzMzr30Exq/ U18wCge7MXOuoo3fL7rgArV0wcPv8tib6007x/u4oiQxlotZLBaxzrNESXIWfmnaDE9j cZdDQqxg7dTy4pApYdrvea3XGvV+qNZf6rj+EXVYluzaX1OK3bMPIJO8ri23rDar08L3 Yf3Q== 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:from:date :message-id:subject:to:cc; bh=ZxW1kNoNYq+nIRbKxQ+OJuPZZtbedkQq6ghCw0HhbMA=; b=AyrkHdELJ4rjn3FoCKDWQfxNs8WBiF3vWHWVKmMcScN81TdZKpA9K3xLilZDUw8WFd 4+4yyjElSDme9mMkCvKvbLFmN4V0ke5pdosTM/B6wETGe4zfnnDMkZ5em1cRzOnpN57h MqI7e4fZ+8kJg+b/ZEJgQFhd3H2qCCuOaZ0EMF5aEMd065D3FTz2vRZ/iltPmSpuaK45 R023GrMX+xF1CMi0zeTXXxePGmFhSSt/e2yMDDDEQODZGjSjDDmDSBadQ2TU2M0xEiVU KHXWwEixZQ9cL91HFGPJUCQqESQ8r0R/2XrbYdzkDNWYGj2PFGOSF9MJCiGBK5zBvb1J xm1Q== X-Gm-Message-State: ABUngvc+8CsCo7IUlRoI1fsehvqYJYEkiAMZxtwlaZXIUQbumerQCxcJ+/m10eHNZy0iRjBvKsqaNP7plsnkig== X-Received: by 10.31.254.135 with SMTP id l129mr3898948vki.36.1477826684226; Sun, 30 Oct 2016 04:24:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.99.4 with HTTP; Sun, 30 Oct 2016 04:24:43 -0700 (PDT) In-Reply-To: References: <44244cfd-c8ad-e0a9-4e70-380a8a8c940c@syberisle.net> Date: Sun, 30 Oct 2016 12:24:43 +0100 Message-ID: To: Nikita Popov Cc: Levi Morrison , David Lundgren , internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Allow Iterator to be used with current, next, reset, key functions From: rasmus@mindplay.dk (Rasmus Schultz) With regards to deprecating array-functions that operate on the internal pointer - I'd like to just remind you of the fact that some of these functions, reset() and end() in particular, are often used not because someone cares about moving the internal pointer, but as a means of getting the first/last items of an array. If the internal pointers are removed, I'd like to suggest we improve the reset() and end() functions rather than removing them - there is an annoyance with these two functions presently: because they operate on the internal pointer, the force you to introduce often meaningless intermediary variables. That is, for example: $last = end(explode(",", $comma_separated_values)); Doesn't work. One is forced to introduce a variable: $parts = explode(",", $comma_separated_values); $last = end($parts); If internal pointers are removed, maybe the reset() and end() functions could be made to actually work consistently? Whether applied to an expression or variable. On Sat, Oct 29, 2016 at 10:06 PM, Nikita Popov wrote: > On Fri, Oct 28, 2016 at 2:43 PM, Levi Morrison wrote: > >> On Wed, Oct 26, 2016 at 7:42 AM, David Lundgren >> wrote: >> > Greetings, >> > >> > As suggested by several reviewers of a PR[1] I recently submitted, I'd >> > like to get feedback on letting custom Iterators be used in the current, >> > next, reset, and key functions. If this is something to move forward >> > with, I'll need some help with the RFC process. >> > >> > Recent experiences trying to use these functions with a custom Iterator, >> > and a bug[2], led me to try and fix this. BC will occur when an object >> > implementing Iterator is passed to one of the functions, as the >> > interface methods will be called, instead of returning the objects >> > properties. The old behavior should be maintained for classes that do >> > not implement Iterator. >> > >> > [1] https://github.com/php/php-src/pull/2176 >> > [2] https://bugs.php.net/bug.php?id=49369 >> > >> > Thanks, >> > Dave >> > -- >> > David Lundgren >> > dlundgren@syberisle.net >> > 808.639.0365 >> > GPG: 0x26F54D7F >> > >> > -- >> > PHP Internals - PHP Runtime Development Mailing List >> > To unsubscribe, visit: http://www.php.net/unsub.php >> >> I can't seem to recall specifics anymore but I do believe some people >> would greatly prefer to remove the internal array pointer for >> iteration and deprecate these functions. Maybe someone else can >> remember more? Nikita and Bob, maybe? >> > > Yeah, I'm one of those people. In PHP 7 the most important user of the IAP, > foreach, was switched to use a more robust mechanism. I believe that at > this point, the concept of an internal array pointer has outlived its > usefulness and we should be working toward removing any APIs that publicly > expose it, including each and the next/current/key family of functions. I > will propose to deprecate each() in particular for PHP 7.2, because it is > both more problematic and more useless than the others, but I'd like to see > the others go away in the long term as well. If people want fine-grained > control over array iteration, they should use an external iterator (aka > ArrayIterator), not an internal one. > > Nikita