|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46227 wrong initial pointer for CachingIterator and RecursiveCachingIterator
Submitted: 2008-10-04 14:52 UTC Modified: 2022-01-17 11:29 UTC
Avg. Score:3.8 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: exceptione at hotmail dot com Assigned: cmb (profile)
Status: Duplicate Package: SPL related
PHP Version: 5.2.10 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.
Block user comment
Status: Assign to:
Bug Type:
From: exceptione at hotmail dot com
New email:
PHP Version: OS:


 [2008-10-04 14:52 UTC] exceptione at hotmail dot com
In order to use a new CachingIterator of RecursiveCachingIterator, one needs to do a rewind() or next() to get current() pointing to the first element. This is unlike the other Iterators.

Reproduce code:
$arr = array(1,2,3,4,5);
$it = new CachingIterator(new ArrayIterator($arr));
var_dump($it->current()); echo PHP_EOL;
var_dump($it->current()); echo PHP_EOL;

Expected result:
int 1
int 2

Actual result:
int 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-04 14:57 UTC] exceptione at hotmail dot com
Note that one get get the expected behaviour from the implementation in ext\spl\internal\ after correcting the following bugs in that file:

add private $flags as class member
on line 50 change flags into $flags
on line 50 delete CIT_ prefix
 [2008-10-05 18:02 UTC]
That looks like #44063
 [2008-10-06 10:23 UTC] exceptione at hotmail dot com
Might be the case indeed. I wanted to add a comment over there, but I am not allowed to. So here:

> How could you say this is not a bug? Please reconsider!
> There is one invariant which says: ?the pointer in all new iterators points at the first element of the collection that has to be iterated.?
> Hence a new iterator a that wraps another new iterator b points to the first element of b.

I am very happy with and grateful for the SPL contribution to php. I really hope the behaviour from all iterators from the iterator zoo will be consistent. I think these bugs are certainly no bogus. It's a contract violation and that's painful to me.
 [2008-10-24 09:24 UTC]
Marcus, deal with this.
 [2015-09-07 20:18 UTC]
-Status: Assigned +Status: Verified
 [2015-09-07 20:18 UTC]
Indeed, basically that's the same issue as reported in bug #44063:
the constructor misses to properly initialize the OuterIterator.
 [2017-10-24 05:26 UTC]
-Status: Verified +Status: Assigned
 [2017-10-24 07:26 UTC]
-Status: Assigned +Status: Open -Assigned To: colder +Assigned To:
 [2022-01-17 11:29 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2022-01-17 11:29 UTC]
Closing as duplicate of <>.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Feb 26 12:01:26 2024 UTC