Re: Allow Iterator to be used with current, next, reset, key functions
| From: | Rowan Collins | Date: | Sun, 30 Oct 2016 17:19:24 +0000 |
| Subject: | Re: Allow Iterator to be used with current, next, reset, key functions | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96657@lists.php.net to get a copy of this message | ||
On 30/10/2016 12:07, Fleshgrinder wrote:
I think it makes much more sense to deprecate all of them and introduce new ones that work in the way we want them to for several reasons.I've always felt like these functions were "missing" from the language - there are a number of ways you *can* get the first or last item in an array, but all have side effects, because they're not designed for this purpose. It just so happens that - most of the time - reset() and end() have the smallest side effects. I can't remember if it was an earlier discussion here, or somewhere else, that pointed to getting the first and last *key* as an extra use case worth considering. It's currently possible (if awkward) with key(). I think it would make sense to, in the same version: - deprecate reset(), end(), each(), and key() - introduce array_first(), array_last(), array_first_key() and array_last_key() - document replacements for whatever other use cases we can find examples of Doing them all at once makes the messaging much clearer - this family of functions is going to be removed; and here are the new functions you can start using immediately instead. Regards, -- Rowan Collins [IMSoP]end()andreset()would have to continue working as they do until the next major release since people who use them might rely on the way they work. This means in effect that nobody can make her PHP 7 code PHP 8 ready up front. Instead we could directly introducearray_first()andarray_last()with the next feature release -- even if the others are not deprecated -- and everyone can update their code or at least use it in new code.