Files
php-src/ext/simplexml/tests/attributes_dimension_write.phpt
Ilia Alshanetsky fc7a6b9007 [SimpleXML] Fix creating new attributes via attributes() dimension write
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.

Closes GH-23500
2026-08-30 11:03:49 -04:00

31 lines
650 B
PHP

--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"/>