PHP 8.5.0 Alpha 1 available for testing

Voting

: max(eight, six)?
(Example: nine)

The Note You're Voting On

jerome at chaman dot ca
5 years ago
"cached iteration over another iterator" means this iterator is always one step behind the inner iterator. In other words, the "first" iteration will yield null:

<?php

$cit
= new CachingIterator( new ArrayIterator( [ 'a', 'b', 'c'] ) );

echo
$cit->current() ); // null
echo $cit->getInnerIterator()->current() ); // "a"

while($cit->hasNext()){

// we start with a "next" since the "first" item is null
$cit->next();
echo
$cit->current(), '<br>';

}
?>

iterating this way gives us an access, ahead, to the future item (aka current item of the inner iterator)

<< Back to user notes page

To Top