On Sun, Oct 30, 2016 at 12:24 PM, Rasmus Schultz <ras...@mindplay.dk> wrote:

> With regards to deprecating array-functions that operate on the
> internal pointer - I'd like to just remind you of the fact that some
> of these functions, reset() and end() in particular, are often used
> not because someone cares about moving the internal pointer, but as a
> means of getting the first/last items of an array.
>
> If the internal pointers are removed, I'd like to suggest we improve
> the reset() and end() functions rather than removing them - there is
> an annoyance with these two functions presently: because they operate
> on the internal pointer, the force you to introduce often meaningless
> intermediary variables.
>
> That is, for example:
>
>     $last = end(explode(",", $comma_separated_values));
>
> Doesn't work. One is forced to introduce a variable:
>
>     $parts = explode(",", $comma_separated_values);
>     $last = end($parts);
>
> If internal pointers are removed, maybe the reset() and end()
> functions could be made to actually work consistently? Whether applied
> to an expression or variable.
>

Yeah, I've been thinking about this as well. reset() and end() do seem to
be the most commonly used IAP functions -- while nobody actually cares
about their effect on the IAP. The thing is, if we remove all other
functions that allow users to inspect the IAP, then we can simply change
reset() and end() to return the first/last element. As they would no longer
actually modify the array, they would no longer accept their argument by
reference, so end(explode(...)) would also become legal (and additionally,
they would no longer have to do a full copy of their argument, like they
currently sometimes need to do).

Nikita

Reply via email to