SplFixedArray Is Now An IteratorAggregate
SplFixedArrayused to be anIterator, and is now an IteratorAggregate`.
They don’t have strictly identical behaviors. They’re both iterable but they go about it two completely different ways: Iterator means the object modifies itself during iteration, and `IteratorAggregater`` means the object remains unchanged because it uses a proxy object to handle iteration.
Note that is it not possible to extends both at the same time: they are incompatible.
PHP code
<?php
$array = new SplFixedArray(5);
var_dump($array instanceof Iterator);
var_dump($array instanceof IteratorAggregate);
?>
Before
bool(true)
bool(false)
After
bool(false)
bool(true)
PHP version change
This behavior changed in 8.0.
See Also
- Standard PHP Library (SPL)
- Classes extending IteratorAggregate can not implement RecursiveIterator
- Introduction to Iterators and Generators in PHP
- IteratorAggregate
- Iterator