[php-src] PHP-8.5: Merge branch 'PHP-8.4' into 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:04:27-04:00
Commit: https://github.com/php/php-src/commit/85417195b9c0c373861827675aa0c5401646c1af
Raw diff: https://github.com/php/php-src/commit/85417195b9c0c373861827675aa0c5401646c1af.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
[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 a5d2cfe2c037..220aa49869c5 100644
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,10 @@ PHP NEWS
empty Location header. (iliaal)
. Fixed read buffer compaction in php_stream_filter_flush(). (crystarm)
+- SimpleXML:
+ . Fixed writing to a dimension of the object returned by attributes() not
+ creating the attribute. (Ilia Alshanetsky)
+
- Zip:
. Fixed bug GH-17787 (ZipArchive stream stops reading early when the archive
is freed while the stream is still open). (Eyüp Can Akman)
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index b51ee3509b75..06c627963c89 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -438,8 +438,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"/>