Skip to content

Conversation

@PCouaillier
Copy link

Hello,

Is there any reason to prefer the anonymous function than the IteratorIterator ?

@drupol
Copy link

drupol commented Sep 26, 2020

I guess it's because you can only pass an object to IteratorIterator, and not an array.

"Argument 1 passed to IteratorIterator::__construct() must implement interface Traversable, array given"

@PCouaillier
Copy link
Author

The previous lines already check the fact that it is not an array

    if (\is_array($iterable)) {
        return new \ArrayIterator($iterable);
    }
    if ($iterable instanceof \Iterator) {
        return $iterable;
    }
    if ($iterable instanceof \IteratorAggregate) {
        return $iterable->getIterator();
    }

@drupol
Copy link

drupol commented Sep 27, 2020

Fair enough, didn't see that part when I wrote the comment. Ignore my feedback then :-)

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

Successfully merging this pull request may close these issues.

2 participants