Re: [pr-645] Add offset to reset() and end()
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)