php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50981 CachingIterator::hasNext() does not return correct value in some cases
Submitted: 2010-02-09 23:05 UTC Modified: 2017-10-24 07:25 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: clarity1285 at gmail dot com Assigned:
Status: Open Package: SPL related
PHP Version: 5.3.1 OS: Mac OS X
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-02-09 23:05 UTC] clarity1285 at gmail dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-12 17:04 UTC] aleksey dot v dot korzun at gmail dot com
I'm experiencing the same issue.
 [2010-02-12 17:23 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2010-02-12 18:49 UTC] clarity1285 at gmail dot com
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".
 [2011-11-16 13:54 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: colder
 [2017-10-24 07:25 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: colder +Assigned To:
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC