[php-src] master: Merge branch 'PHP-8.5'
Ilia Alshanetsky <[email protected]>
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Ilia Alshanetsky (iliaal)
Date: 2026-08-30T11:05:13-04:00
Commit: https://github.com/php/php-src/commit/860dda81f711ada1d710f16602d8ab3906b2356e
Raw diff: https://github.com/php/php-src/commit/860dda81f711ada1d710f16602d8ab3906b2356e.diff
Merge branch 'PHP-8.5'
* PHP-8.5:
[SimpleXML] Fix creating new attributes via attributes() dimension write
Changed paths:
A ext/simplexml/tests/attributes_dimension_write.phpt
M NEWS
M ext/simplexml/simplexml.c
Diff:
diff --git a/NEWS b/NEWS
index cc52980d890b..bd17cf9bf8e6 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,10 @@ PHP NEWS
. Io\Poll\Context::wait() now rejects a $maxEvents value greater than
INT_MAX instead of truncating it. (marc-mabe)
+- SimpleXML:
+ . Fixed writing to a dimension of the object returned by attributes() not
+ creating the attribute. (Ilia Alshanetsky)
+
27 Aug 2026, PHP 8.6.0beta2
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 94c538a40488..74d310e9d938 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -436,8 +436,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
if (sxe->iter.type == SXE_ITER_ATTRLIST) {
access_mode = SXE_ACCESS_ATTRIBS;
- node = php_sxe_get_first_node_non_destructive(sxe, node);
- attr = (xmlAttrPtr)node;
+ attr = (xmlAttrPtr)php_sxe_get_first_node_non_destructive(sxe, node);
test = sxe->iter.name != NULL;
} else if (sxe->iter.type != SXE_ITER_CHILD) {
mynode = node;
diff --git a/ext/simplexml/tests/attributes_dimension_write.phpt b/ext/simplexml/tests/attributes_dimension_write.phpt
new file mode 100644
index 000000000000..8721dc7dc7c2
--- /dev/null
+++ b/ext/simplexml/tests/attributes_dimension_write.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Creating new attributes via dimension and property writes on attributes()
+--FILE--
+<?php
+$x = simplexml_load_string('<r a="1"/>');
+$x->attributes()['new'] = 'v';
+echo $x->asXML();
+
+$a = simplexml_load_string('<r/>');
+$a->attributes()['created'] = 'yes';
+echo $a->asXML();
+
+$b = simplexml_load_string('<r a="1"/>');
+$attrs = $b->attributes();
+$attrs->other = 2;
+echo $b->asXML();
+
+$c = simplexml_load_string('<r a="1"/>');
+$c->attributes()['a'] = '2';
+echo $c->asXML();
+?>
+--EXPECT--
+<?xml version="1.0"?>
+<r a="1" new="v"/>
+<?xml version="1.0"?>
+<r created="yes"/>
+<?xml version="1.0"?>
+<r a="1" other="2"/>
+<?xml version="1.0"?>
+<r a="2"/>