Bug #46227 [Asn->Ver]: wrong initial pointer for CachingIterator and RecursiveCachingIterator
Edit report at https://bugs.php.net/bug.php?id=46227&edit=1
ID: 46227
Updated by: cmb@php.net
Reported by: exceptione at hotmail dot com
Summary: wrong initial pointer for CachingIterator and
RecursiveCachingIterator
-Status: Assigned
+Status: Verified
Type: Bug
Package: SPL related
Operating System: *
PHP Version: 5.2.10
Assigned To: colder
Block user comment: N
Private report: N
New Comment:
Indeed, basically that's the same issue as reported in bug #44063:
the constructor misses to properly initialize the OuterIterator.
Previous Comments:
------------------------------------------------------------------------
[2008-10-24 09:24:31] jani@php.net
Marcus, deal with this.
------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=46227&edit=1
Thread (9 messages)