php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47497 CachingIterator doesn't work with an IteratorIterator inside it
Submitted: 2009-02-24 16:31 UTC Modified: 2009-05-04 10:05 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: doctorrock83 at gmail dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.*, 6CVS (2009-04-30) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: doctorrock83 at gmail dot com
New email:
PHP Version: OS:

 

 [2009-02-24 16:31 UTC] doctorrock83 at gmail dot com
Description:
------------
CachingIterator doesn't work if its innerIterator is an instance of IteratorIterator.

The use-case provided here might seem strange as the IteratorIterator is not necessary.
However, it would become necessary for a use case dealing with a Traversable class such as PDOStatement, and the bug stays the same.

Additionnaly, we actually have to call next() manually but it should be called internaly.
This leads to another bug which has already been reported at #46227

Reproduce code:
---------------
$it = new ArrayIterator(range('a','z');
$cache = new CachingIterator(new IteratorIterator($it));
$cache->next();
var_dump($cache->current());
var_dump($cache->hasNext());

Expected result:
----------------
1 and TRUE

Actual result:
--------------
NULL and FALSE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-24 16:34 UTC] doctorrock83 at gmail dot com
"Expected result" is 
'a' and TRUE 
and not
1 and TRUE
as you might have guessed
 [2009-05-04 10:05 UTC] johannes@php.net
You have to call $cache->rewind(); first else the iterator in in a not defined state.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Mar 23 11:01:26 2019 UTC