Description:
------------
When there are 11 total items and you use a LimitIterator to get the
first 10, CachingIterator::hasNext() returns false even though there are
more than 10 items in the initial set.
If there are 12 total items it works as expected.
Reproduce code:
---------------
$items = new ArrayObject(range(1,11));
echo 'there are ' . $items->count() . ' total items' . "\r\n";
$cachingIterator = new CachingIterator($items->getIterator());
$limitIterator = new LimitIterator($cachingIterator, 0, 10);
$i = 0;
foreach ($limitIterator as $item) {
++$i;
}
echo 'first page has ' . $i . ' items' . "\r\n";
if ($cachingIterator->hasNext()) {
echo 'there is a next page';
} else {
echo 'there is no next page';
}
Expected result:
----------------
The code should output:
there are 11 total items
first page has 10 items
there is a next page
Actual result:
--------------
The code outputs:
there are 11 total items
first page has 10 items
there is no next page

Tested with PHP 5.3.3-dev snapshot provided, and the issue is still
reproducible.

[2010-02-20 01:00 UTC] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

CachingIterator::hasNext() returns the correct result in this
case, since the inner iterator has no valid next element anymore.
See the slightly modified script[1].
This expected, but not explicitly documented behavior stems from
the fact that a CachingIterator is always one element ahead, which
it already caches. For details see the explanation in my comment
on bug #49607.
Fixing the supplied test script is as simple as calling
CachingIterator::valid() instead of CachingIterator::hasNext().
[1] <https://3v4l.org/5JtJA>