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
asika32764
changed the title
PHP 8.4 classList works not correctly if HTMLElement cloned.
PHP 8.4 classList works not correctly if copy HTMLElement by clone keyword.
Jun 3, 2025
…ement by clone keyword.
The $classList property is special in the sense that it's a cached
object instance per (HTML)Element instance. The reason for this design
is because it has the [[SameObject]] IDL attribute.
Cloning in PHP also clones the properties, so it also clones the cached
instance. To solve this, we undo this by resetting the backing storage.
Some clarification as to why cloneNode behaves correctly but clone does not: clone creates a copy of the entire object, while cloneNode only copies the tree structure and then creates a new object instance. This is significant if you have custom properties on an Element instance, or you extend the Element class yourself.
The reason why TokenList is uncloneable is because the DOM spec requires it to always be the same object for a single Element. Therefore, the class can't be cloneable as it would violate this constraint.
Uh oh!
There was an error while loading. Please reload this page.
Description
The following code:
Resulted in this output:
But I expected this output instead:
3v4l.org: https://3v4l.org/eaosZ#v8.4.7
If try to clone
classList
will raise an error:But
$ele2 = $ele->cloneNode(true)
works.PHP Version
Operating System
Windows 11 and 3v4l.org
The text was updated successfully, but these errors were encountered: