#50981 [Opn->Fbk]: CachingIterator::hasNext() does not return correct value in some cases

From: Date: Fri, 12 Feb 2010 17:23:50 +0000
Subject: #50981 [Opn->Fbk]: CachingIterator::hasNext() does not return correct value in some cases
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-147496@lists.php.net to get a copy of this message
 ID:               50981
 Updated by:       jani@php.net
 Reported By:      clarity1285 at gmail dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         SPL related
 Operating System: Mac OS X
 PHP Version:      5.3.1
 New Comment:

Please try using this snapshot:

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

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




Previous Comments:
------------------------------------------------------------------------

[2010-02-12 17:04:55] aleksey dot v dot korzun at gmail dot com

I'm experiencing the same issue.

------------------------------------------------------------------------

[2010-02-09 23:05:48] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50981&edit=1



Thread (7 messages)

« previous php.bugs (#147496) next »