Re: [pr-645] Add offset to reset() and end()

From: Date: Fri, 18 Apr 2014 08:58:54 +0000
Subject: Re: [pr-645] Add offset to reset() and end()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-73741@lists.php.net to get a copy of this message
On Fri, Apr 18, 2014 at 2:39 AM, Tjerk Meesters <tjerk.meesters@gmail.com>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).
>
> 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 => $v) { ... }

Nikita


Thread (7 messages)

« previous php.internals (#73741) next »