Skip to content

simplexml: filter addChild() result by the created element's namespace - #23599

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:promote/simplexml-addchild-ns
Open

simplexml: filter addChild() result by the created element's namespace#23599
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:promote/simplexml-addchild-ns

Conversation

@iliaal

@iliaal iliaal commented Sep 6, 2026

Copy link
Copy Markdown
Member

SimpleXMLElement::addChild() built the returned element with the prefix the caller passed in rather than the one the new node ended up in, so a child added through that returned object was filtered against the wrong namespace and could not be reached by property name. Taking the prefix from newnode->ns fixes all three cases: an explicit a:kid with a matching uri, a bare kid with a uri, and a bare kid under a prefixed parent where xmlNewChild inherits the parent's prefix.

The filter keys on the prefix rather than the href deliberately. node_as_zval() installs no filter at all when the prefix is null or empty, so switching to href matching would start filtering the default-namespace case that currently has none.

@iliaal
iliaal requested a review from devnexen as a code owner September 6, 2026 15:07
addChild() built the returned SimpleXMLElement with the prefix the caller
passed in, not the one the new node ended up in, so a child added through
that object was filtered against the wrong namespace and was invisible by
property name. Take the prefix from newnode->ns instead. The filter keys
on the prefix rather than the href because node_as_zval() installs no
filter at all for a prefixless namespace, and switching to href would
start filtering the default-namespace case that today has none.

Closes phpGH-23599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant