Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

Extension

© 2023-2026, Damien Seguy - Exakat