Merged
Conversation
37e795b to
9173e41
Compare
j0k3r
reviewed
Mar 18, 2024
Owner
j0k3r
left a comment
There was a problem hiding this comment.
I still found it more readable to read foreach than for loop.
So it's ok for me
Contributor
Author
|
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.
j0k3r
approved these changes
Oct 11, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.