Re: [pr-645] Add offset to reset() and end()
On 18 April 2014 09:58, Nikita Popov <nikita.ppv@gmail.com> wrote:
> 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).
>
The last time that I can remember discussion of something like array_seek()
[1]–which is what this seems like it actually wants to be–the reception was
fairly positive, but the idea just fizzled out. I’d recommend looking 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 => $v) { ... }
>
> Nikita
>
Thread (7 messages)