Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
3v4l.org/U61Ii
LimitIterator_::rewind rewind at the beginning of the foreach...
> TestFilterIterator_::rewind ...and the inner iterator
> > ArrayIterator_::rewind ...and again. now testfilteriterator must look for the first accept()able value
> > ArrayIterator_::valid iterate on arrayiterator...
> > ArrayIterator_::current ...
> > ArrayIterator_::key ...
> > TestFilterIterator_::accept ...and test the first value it found
accept (call #1 on [0]=>'0')
> > ArrayIterator_::next value ('0') was not accepted
> > ArrayIterator_::valid continue iterating...
> > ArrayIterator_::current ...
> > ArrayIterator_::key ...
> > TestFilterIterator_::accept ...and test again. this time it will be valid
accept (call #2 on [1]=>'a')
> TestFilterIterator_::valid limititerator validates the testfilteriterator
> TestFilterIterator_::valid and begins its own iteration...
> TestFilterIterator_::current ...
> TestFilterIterator_::key ...
LimitIterator_::valid foreach begins iteration...
LimitIterator_::current ...
LimitIterator_::key ...
array(2) { and the body of the loop begins
[0]=>
int(1)
[1]=>
string(1) "a"
}
LimitIterator_::next foreach moves to the next element...
> TestFilterIterator_::next ...
> > ArrayIterator_::next ...and now testfilteriterator must find the next accept()able value
> > ArrayIterator_::valid continue iteration...
> > ArrayIterator_::current ...
> > ArrayIterator_::key ...
> > TestFilterIterator_::accept ...and test this value
accept (call #3 on [2]=>'0')
> > ArrayIterator_::next not accepted, keep going...
> > ArrayIterator_::valid ...
> > ArrayIterator_::current ...
> > ArrayIterator_::key ...
> > TestFilterIterator_::accept ...until this value is accepted
accept (call #4 on [3]=>'b')
> TestFilterIterator_::valid limititerator validates testfilteriterator again...
> TestFilterIterator_::current ...
> TestFilterIterator_::key ...
LimitIterator_::valid foreach resumes the loop...
LimitIterator_::current ...
LimitIterator_::key ...
array(2) { loop body
[0]=>
int(3)
[1]=>
string(1) "b"
}
LimitIterator_::next continue iteration...
> TestFilterIterator_::next ...
> > ArrayIterator_::next ...and validate...
> > ArrayIterator_::valid ...
> > ArrayIterator_::current ...
> > ArrayIterator_::key ...
> > TestFilterIterator_::accept ...this value fails
accept (call #5 on [4]=>'0')
> > ArrayIterator_::next resume...
> > ArrayIterator_::valid ...
> > ArrayIterator_::current ...
> > ArrayIterator_::key ...
> > TestFilterIterator_::accept ...this value passes
accept (call #6 on [5]=>'c')
LimitIterator_::valid limititerator fails validation because it has passed the limit of 2 items and the loop ends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.