Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73742 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75112 invoked from network); 18 Apr 2014 23:51:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2014 23:51:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=petercowburn@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=petercowburn@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) X-PHP-List-Original-Sender: petercowburn@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qa0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:44968] helo=mail-qa0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/40-04730-D8AB1535 for ; Fri, 18 Apr 2014 19:51:43 -0400 Received: by mail-qa0-f42.google.com with SMTP id k15so2073912qaq.29 for ; Fri, 18 Apr 2014 16:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=XqRZ8SfHN/PSQ1h3YJg+7wbxBALxLsn/AOmsB4JdPzQ=; b=V/gViquXT6M9eIAFMBWYTYDOPmzzIovk19Z934NRXRWEHIdS7GpBgoDbVmgPZqiBkR bPC6uG/s1AZkM1/D7rmjgo/OgjJ3QslYIgwEFyfyyAbl3Bm+oGYFr02Pltp4eARtTe12 tqJhpiiAc10yKiPBJjRsKbJYFjwWfBGVByBv0gWbN3Jlklszcb9fTS5fZYKjhfG/+AZ9 tFKxENLQAjtFOxXdK0v4wcJaMYjlD5Ojjf31Ph62DnLhukQCFTwKcFrM9/2dYrxeSrlU FWQm+6eVJsxvIFX5gp1mT0vGsfpsZM3rnY5gBXVRxOLJaxJOIdogpjY5wiGMJLX2ona4 RyXA== X-Received: by 10.224.40.197 with SMTP id l5mr21843311qae.83.1397865098988; Fri, 18 Apr 2014 16:51:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.96.66.72 with HTTP; Fri, 18 Apr 2014 16:50:58 -0700 (PDT) In-Reply-To: References: Date: Sat, 19 Apr 2014 00:50:58 +0100 Message-ID: To: Nikita Popov Cc: Tjerk Meesters , PHP Internals Content-Type: multipart/alternative; boundary=047d7b674408ab526304f759d481 Subject: Re: [PHP-DEV] [pr-645] Add offset to reset() and end() From: petercowburn@gmail.com (Peter Cowburn) --047d7b674408ab526304f759d481 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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=93t= he reception was fairly positive, but the idea just fizzled out. I=E2=80=99d recommend look= ing back over the archives for other similar discussions. 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 manual > array iteration with them is both somewhat unsafe (think nested iteration= ) > 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 > --047d7b674408ab526304f759d481--