php.net |  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
Votes:3
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
Description:
------------
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;
$it->next();
var_dump($it->current()); echo PHP_EOL;

Expected result:
----------------
int 1
int 2


Actual result:
--------------
null
int 1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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\cachingiterator.inc 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] felipe@php.net
That looks like #44063
 [2008-10-06 10:23 UTC] exceptione at hotmail dot com

 [2008-10-24 09:24 UTC] jani@php.net
Marcus, deal with this.
 [2015-09-07 20:18 UTC] cmb@php.net
-Status: Assigned +Status: Verified
 [2015-09-07 20:18 UTC] cmb@php.net
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] kalle@php.net
-Status: Verified +Status: Assigned
 [2017-10-24 07:26 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