#46227 [Opn->Asn]: wrong initial pointer for CachingIterator and RecursiveCachingIterator
ID: 46227
Updated by: jani@php.net
Reported By: exceptione at hotmail dot com
-Status: Open
+Status: Assigned
Bug Type: SPL related
Operating System: windos XP sp3
PHP Version: 5.2.6
-Assigned To:
+Assigned To: helly
New Comment:
Marcus, deal with this.
Previous Comments:
------------------------------------------------------------------------
[2008-10-06 10:23:25] 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-05 18:02:10] felipe@php.net
That looks like #44063
------------------------------------------------------------------------
[2008-10-04 14:57:34] 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-04 14:52:05] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46227&edit=1
Thread (9 messages)