Proposal: Add ReverseArrayIterator and ForwardArrayIterator to SPL
| From: | Levi Morrison | Date: | Wed, 03 Feb 2021 15:37:41 +0000 |
| Subject: | Proposal: Add ReverseArrayIterator and ForwardArrayIterator to SPL | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-113061@lists.php.net to get a copy of this message | ||
Hello, everyone!
This proposal adds two new classes to the SPL:
-
Spl\ReverseArrayIterator. It iterates over an array in reverse
order. It does not duplicate the array.
- Spl\ForwardArrayIterator. It iterates over an array in forward
(normal) order. It does not duplicate the array.
They both implement Countable which returns the count() of the
array. The [PR][1] has some examples and discusses why I am proposing
ForwardArrayIterator when there is already ArrayIterator, the
short of which is for performance. There are timing numbers in [one of
the comments][2].
When it comes time to vote I may merge this into another RFC with
[CachedIterable by Tyson Andre][3], which I recommend readers also
take a look at. Whether we team up for the RFC vote or not, I wanted
to get this out there for discussion and review.
[1]: https://github.com/php/php-src/pull/6535
[2]: https://github.com/php/php-src/pull/6535#issuecomment-769179450
[3]: https://github.com/php/php-src/pull/6655