[php-src] master: Merge branch 'PHP-8.5'

From: Date: Tue, 08 Sep 2026 10:28:13 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141127@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-09-08T06:26:50-04:00 Commit: https://github.com/php/php-src/commit/475811a1866abeb4f8215b9210656c6ec768bb95 Raw diff: https://github.com/php/php-src/commit/475811a1866abeb4f8215b9210656c6ec768bb95.diff Merge branch 'PHP-8.5' * PHP-8.5: simplexml: fix addChild() namespace filter on the returned element Changed paths: A ext/simplexml/tests/addChild_ns_filter_returned_element.phpt M NEWS M ext/simplexml/simplexml.c Diff: diff --git a/NEWS b/NEWS index 1b2e879fcaf5..205b2f071ff8 100644 --- a/NEWS +++ b/NEWS @@ -106,6 +106,9 @@ PHP NEWS - SimpleXML: . Fixed writing to a dimension of the object returned by attributes() not creating the attribute. (Ilia Alshanetsky) + . Fixed child elements of the element returned by + SimpleXMLElement::addChild() not being accessible by property name when + namespaces are involved. (Ilia Alshanetsky) - Streams: . Added so_rcvbuf and so_sndbuf stream socket context options, setting the diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 74d310e9d938..75d859eea4ac 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1671,6 +1671,7 @@ PHP_METHOD(SimpleXMLElement, addChild) xmlNsPtr nsptr = NULL; xmlChar *localname, *prefix = NULL; bool free_localname = false; + const xmlChar *retprefix = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!", &qname, &qname_len, &value, &value_len, &nsuri, &nsuri_len) == FAILURE) { @@ -1721,7 +1722,11 @@ PHP_METHOD(SimpleXMLElement, addChild) } } - node_as_zval_str(sxe, newnode, return_value, SXE_ITER_NONE, localname, prefix, 0); + if ((prefix != NULL || nsuri != NULL) && newnode->ns != NULL) { + retprefix = newnode->ns->prefix; + } + + node_as_zval_str(sxe, newnode, return_value, SXE_ITER_NONE, localname, retprefix, 1); if (free_localname) { xmlFree(localname); diff --git a/ext/simplexml/tests/addChild_ns_filter_returned_element.phpt b/ext/simplexml/tests/addChild_ns_filter_returned_element.phpt new file mode 100644 index 000000000000..b0452f30182b --- /dev/null +++ b/ext/simplexml/tests/addChild_ns_filter_returned_element.phpt @@ -0,0 +1,56 @@ +--TEST-- +SimpleXMLElement::addChild() wrong namespace filter on returned element +--EXTENSIONS-- +simplexml +--FILE-- +<?php +$x = new SimpleXMLElement('<r xmlns:a="http://example.com"/>'); +$c = $x->addChild('a:kid', null, 'http://example.com'); +$c->addChild('inner', 'v'); +echo trim($x->asXML()), "\n"; +echo (string) $c->inner, "\n"; +var_dump(isset($c->inner)); + +$y = new SimpleXMLElement('<r xmlns:a="http://example.com"/>'); +$d = $y->addChild('kid', null, 'http://example.com'); +$d->addChild('inner', 'w'); +echo trim($y->asXML()), "\n"; +echo (string) $d->inner, "\n"; + +$z = new SimpleXMLElement('<r/>'); +$e = $z->addChild('a:kid'); +$e->addChild('inner', 'z'); +echo trim($z->asXML()), "\n"; +echo (string) $e->inner, "\n"; +var_dump(isset($e->inner)); + +$q = new SimpleXMLElement('<p:r xmlns:p="http://example.com/p"/>'); +$f = $q->addChild('kid'); +$f->addAttribute('id', '7'); +echo trim($q->asXML()), "\n"; +echo (string) $f['id'], "\n"; + +$m = new SimpleXMLElement('<r xmlns:a="http://example.com"/>'); +$g = $m->addChild('kid', null, 'http://example.com'); +$g->addAttribute('id', '8'); +echo trim($m->asXML()), "\n"; +var_dump(isset($g['id'])); +?> +--EXPECT-- +<?xml version="1.0"?> +<r xmlns:a="http://example.com"><a:kid><a:inner>v</a:inner></a:kid></r> +v +bool(true) +<?xml version="1.0"?> +<r xmlns:a="http://example.com"><a:kid><a:inner>w</a:inner></a:kid></r> +w +<?xml version="1.0"?> +<r><kid><inner>z</inner></kid></r> +z +bool(true) +<?xml version="1.0"?> +<p:r xmlns:p="http://example.com/p"><p:kid id="7"/></p:r> +7 +<?xml version="1.0"?> +<r xmlns:a="http://example.com"><a:kid id="8"/></r> +bool(false)

« previous php.cvs (#141127) next »