Skip to content

[SimpleXML] Fix creating new attributes via attributes() dimension write - #264

Open
iliaal wants to merge 1 commit into
PHP-8.4from
fix/sxml-attr-dim-84
Open

[SimpleXML] Fix creating new attributes via attributes() dimension write#264
iliaal wants to merge 1 commit into
PHP-8.4from
fix/sxml-attr-dim-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Writing to a dimension of the object returned by SimpleXMLElement::attributes(), such as $x->attributes()["new"] = "v", silently did nothing when the attribute did not already exist, because sxe_prop_dim_write() replaced the element node with the first attribute node while resolving an SXE_ITER_ATTRLIST iterator, so xmlNewProp() was either called on a non-element node or never reached at all when the element had no attributes yet. The fix keeps the element node in place and only resolves the start of the attribute list, making dimension writes on attributes() behave like the equivalent $x["new"] = "v" path; property writes on the attributes() object share this code path and are fixed as well, while the read, exists, and unset handlers are unaffected since they have no creation semantics.

sxe_prop_dim_write() overwrote the element node with the first attribute
node when resolving an SXE_ITER_ATTRLIST iterator, so xmlNewProp() targeted
a non-element node and was skipped entirely when no attribute existed yet.
Keep the element node in place and resolve only the attribute list start,
so $x->attributes()["new"] = "v" creates the attribute like the symmetric
$x["new"] path; property writes on the attributes() object share the fixed
path while read/exists/unset handlers are unaffected by this defect.
@iliaal iliaal closed this Aug 24, 2026
@iliaal iliaal reopened this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant