-
-
Notifications
You must be signed in to change notification settings - Fork 39
Iterate node lists with foreach #90
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
Conversation
37e795b to
9173e41
Compare
j0k3r
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still found it more readable to read foreach than for loop.
So it's ok for me
|
I have rebased this, deciding to skip the reverse for loops for now – the naïve port to |
0238436 to
4428a1c
Compare
`DOMNode::$childNodes` always contained `DOMNodeList`.
This simplifies the code a bit and will make it slightly easier in case we decide to switch to `foreach` iteration.
This was forgotten in b580cf2.
`DOMNodeList` implements `Traversable`. There are some `for` loops left but we cannot simply replace those: PHP follows the DOM specification, which requires that `NodeList` objects in the DOM are live. As a result, any operation that removes a node list member node from its parent (such as `removeChild`, `replaceChild` or `appendChild`) will cause the next node in the iterator to be skipped. We could work around that by converting those node lists to static arrays using `iterator_to_array` but not sure if it is worth it.
DOMNodeListimplementsTraversable.There are some
forloops left but we cannot simply replace those: PHP follows the DOM specification, which requires thatNodeListobjects in the DOM are live. As a result, any operation that removes a node list member node from its parent (such asremoveChild,replaceChildorappendChild) will cause the next node in the iterator to be skipped.We could work around that by converting those node lists to static arrays using
iterator_to_arraybut not sure if it is worth it.Also add few cleanups I noticed.