You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
That said, the PHP documentation for IteratorIterator also states:
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.
The text was updated successfully, but these errors were encountered: