Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with IteratorIterator #147

Closed
enumag opened this issue Oct 31, 2019 · 1 comment
Closed

Bug with IteratorIterator #147

enumag opened this issue Oct 31, 2019 · 1 comment

Comments

@enumag
Copy link

enumag commented Oct 31, 2019

I have a case where I need to create an Iterator from a \Ds\Vector. Since Vector is Traversable but doesn't implement Iterator or IteratorAggregate I thought I'd just use IteratorIterator. This is however broken.

Testing code:

$vector = new \Ds\Vector(['x']);

$iterator = new IteratorIterator($vector);
var_export($iterator->valid());

$iterator = new ArrayIterator($vector->toArray());
var_export($iterator->valid());

Expected result: truetrue

Actual result: falsetrue

Calling rewind on the IteratorIterator fixes the issue though so maybe it's ok. Not sure. It was just a bit confusing for me.

@enumag enumag changed the title Incompatibility with IteratorIterator Bug with IteratorIterator Oct 31, 2019
@morrisonlevi
Copy link

morrisonlevi commented Jun 27, 2020

It is the general PHP iterator protocol that you must rewind before doing any other iterator operations. Anything else is not guaranteed, as you see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants