Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73770 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82916 invoked from network); 24 Apr 2014 03:28:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Apr 2014 03:28:06 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.179 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.179 mail-ve0-f179.google.com Received: from [209.85.128.179] ([209.85.128.179:43631] helo=mail-ve0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3C/40-13812-4C488535 for ; Wed, 23 Apr 2014 23:28:04 -0400 Received: by mail-ve0-f179.google.com with SMTP id db12so2215551veb.24 for ; Wed, 23 Apr 2014 20:28:01 -0700 (PDT) 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=qIPKIwiC2TBJnxAjjUaXP61lSvPcElZ3ovq5Q4XUP68=; b=TsvO/Sb0HevF9glVd99h4JnWMNy7w6PZsnV+2bw1FPmWDOB8Mvmr6Rf5zjS4nwY93I Y7OQma1mZgc/Xx+rOiemfrmoKpLvX4n1A6ECPD101useQ0ry/NHskeFwHxxPJi3SpM5A krIOX/7h8N62idlyRNEaFgVSCuj/OsAb2gzLR+Nw1HrSlvSSMqUAwedt5iUckR6Lc0Dt b4sFcw9tQgfySZRZC4IWuFrvhjxVjCM5m+e4StkFg/mLrlu7+8hPaORo1fVGO6/jXsy5 E8HOrOCGiYbMgNtbeWSobBvvCJkvySDbcA+QnykOlRXPr4m1lqmK09C4Pnf6Pvm6goBS MTuw== MIME-Version: 1.0 X-Received: by 10.52.116.101 with SMTP id jv5mr23623697vdb.11.1398310081377; Wed, 23 Apr 2014 20:28:01 -0700 (PDT) Received: by 10.58.133.84 with HTTP; Wed, 23 Apr 2014 20:28:01 -0700 (PDT) In-Reply-To: References: Date: Thu, 24 Apr 2014 11:28:01 +0800 Message-ID: To: Peter Cowburn Cc: Nikita Popov , PHP Internals Content-Type: multipart/alternative; boundary=bcaec548a9b7afbbab04f7c16fd4 Subject: Re: [PHP-DEV] [pr-645] Add offset to reset() and end() From: tjerk.meesters@gmail.com (Tjerk Meesters) --bcaec548a9b7afbbab04f7c16fd4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Peter, On Sat, Apr 19, 2014 at 7:50 AM, Peter Cowburn wrot= e: > > > > On 18 April 2014 09:58, Nikita Popov wrote: > >> On Fri, Apr 18, 2014 at 2:39 AM, Tjerk Meesters > >wrote: >> >> > Hi, >> > >> > I've added a PR that satisfies #31375. >> > >> > https://github.com/php/php-src/pull/645 >> > >> > It adds a second optional argument to reset() and end() to specify the >> > number of elements that should be skipped (forward or backward). >> > > The last time that I can remember discussion of something like > array_seek() [1]=E2=80=93which is what this seems like it actually wants = to be=E2=80=93the > reception was fairly positive, but the idea just fizzled out. I=E2=80=99= d > recommend looking back over the archives for other similar discussions. > Thanks for digging up the earlier discussion; taking also into account the other feedback I have received, I have updated the PR: https://github.com/php/php-src/pull/645 It takes some cues from the earlier `array_seek()` proposal but: 1. doesn't update the internal pointer if seek() failed 2. returns boolean result to indicate success / failure 3. is not called `array_seek()` ;-) I would be perfectly okay if this gets shut down as well, but at least I've tried :) Example of "iterate over last 50 array entries": if (array_seek($array, -50, SEEK_END)) { while ($data =3D each($array)) { ... } } > I would be -1 on changing reset() and end() to make them be able to not > reset the array pointer, or not move to the end, respectively; especially > where a neater (IMO) alternative has already been discussed. > > [1] http://markmail.org/thread/sczgritz5jcccnwh [PHP-DEV] array_seek > function > > > >> > >> > Currently, negative offsets are ignored. Should we raise a notice for >> such >> > cases? Something like: >> > >> > "Negative offsets are not supported." >> > >> > Any feedback is welcome. Thanks! >> > >> >> The reset() part seems to already be adequately covered by LimitIterator= . >> Personally I'd prefer not to add any new functionality to >> reset/current/... >> because you oughtn't be using those functions anyway. Trying to do manua= l >> array iteration with them is both somewhat unsafe (think nested iteratio= n) >> and makes for really ugly code. >> >> // skip 10 elements of $it. Can be an ArrayIterator, of course >> foreach (new LimitIterator($it, 10) as $k =3D> $v) { ... } >> >> Nikita >> > > --=20 -- Tjerk --bcaec548a9b7afbbab04f7c16fd4--