|  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: 2017-10-24 07:26 UTC
Avg. Score:3.3 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: exceptione at hotmail dot com Assigned:
Status: Open Package: SPL related
PHP Version: 5.2.10 OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 [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:
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC