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

Should Count restore positions of non-Iterator Traversables? #2690

Closed
jmikola opened this issue May 22, 2017 · 1 comment
Closed

Should Count restore positions of non-Iterator Traversables? #2690

jmikola opened this issue May 22, 2017 · 1 comment

Comments

@jmikola
Copy link
Contributor

jmikola commented May 22, 2017

Q A
PHPUnit version 6.1.4
PHP version 7.1.5
Installation Method N/A

When #1125 implemented support for restoring an Iterator's position after counting, it neglected to handle generators (fixed in #2149), nested IteratorAggregate objects (fixed in #2689), and Traversable objects that do not implement Iterator or IteratorAggregate (fixed in #2642).

With the above fixes, Count now only attempts to restore positions of Iterator objects. I also made the following comment in #2642:

Traversable objects that are neither an Iterator or IteratorAggregate interface may still support rewinding. In that case, we may want to compose them in an IteratorIterator.

That said, the PHP documentation for IteratorIterator also states:

It is important to understand that most classes that do not implement Iterators have reasons as most likely they do not allow the full Iterator feature set. If so, techniques should be provided to prevent misuse, otherwise expect exceptions or fatal errors.

In light of this, I would understand an argument that we should not attempt to rewind a non-Iterator Traversable and closing this issue as "Won't Fix".

Alternatively, if it is worth supporting non-Iterator Traversables by wrapping them in an IteratorIterator, we should consider to fail gracefully if rewinding is not possible. This may entail trying the rewind in a try/catch block and aborting the restoration attempt on an exception.

@sebastianbergmann
Copy link
Owner

Thank you for the analysis of this issue, @jmikola. I am sorry for not replying sooner. Back in May when I first saw this issue "my head exploded".

Now I looked at this issue again ... and "my head exploded" once more. As I would rather not have my head explode, I think I am fine with "won't fix".

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