Giter Site home page Giter Site logo

Comments (2)

damianwadley avatar damianwadley commented on May 31, 2024

This behavior is correct: childNodes is a "live" NodeList, and changing the children is reflected immediately in the list. Which also means the current i now points to what would have been the next child, thus when the loop advances it skips an item.

Javascript implements it that way. Does PHP really want to be different about it?
https://jsfiddle.net/54hoLzqv/
(keep in mind that it's the console output which shows items 1,2,3, while the document had 3 removed and so ends up with items 1,2,4)

Same for attributes, which is also a live NodeList.

Obligatory "this behavior has existed for a really long time so is there a good enough reason to change it now?"

from php-src.

nielsdos avatar nielsdos commented on May 31, 2024

The example is badly chosen, I've corrected the example. Then you can see that the iteration stops despite the list being needing to be live.

Obligatory "this behavior has existed for a really long time so is there a good enough reason to change it now?"

Obligatory "we kind of worked around that issue": https://wiki.php.net/rfc/opt_in_dom_spec_compliance

from php-src.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.