php-readability icon indicating copy to clipboard operation
php-readability copied to clipboard

Iterate more node lists with foreach

Open jtojnar opened this issue 1 year ago • 0 comments

PHP follows the DOM specification, which requires that NodeList objects in the DOM are live. As a result, any operation that removes a NodeList node from its parent (e.g. removeChild, replaceChild or appendChild) will cause the next node in the iterator to be skipped.

Let’s convert those node lists to arrays to make them static to allow us to use foreach and drop the index decrementing.

This will make the code a bit clearer at the cost of slightly more work being performed.

Follow-up to #90

jtojnar avatar Mar 18 '24 22:03 jtojnar