SplFixedArray Is Now An IteratorAggregate¶
SplFixedArray used to be a Iterator, and is now a IteratorAggregate.
They aren’t 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