note 124508 added to class.cachingiterator

From: Date: Sun, 15 Dec 2019 00:37:56 +0000
Subject: note 124508 added to class.cachingiterator
Groups: php.notes 
Request: Send a blank email to php-notes+get-213516@lists.php.net to get a copy of this message
"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) ---- Server IP: 208.43.231.9 Probable Submitter: 82.199.157.54 (proxied: 69.17.233.71) ---- Manual Page -- http://php.net/manual/en/class.cachingiterator.php Edit -- https://master.php.net/note/edit/124508 Del: integrated -- https://master.php.net/note/delete/124508/integrated Del: useless -- https://master.php.net/note/delete/124508/useless Del: bad code -- https://master.php.net/note/delete/124508/bad+code Del: spam -- https://master.php.net/note/delete/124508/spam Del: non-english -- https://master.php.net/note/delete/124508/non-english Del: in docs -- https://master.php.net/note/delete/124508/in+docs Del: other reasons-- https://master.php.net/note/delete/124508 Reject -- https://master.php.net/note/reject/124508 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#213516) next »