mirror of
https://github.com/php/php-src.git
synced 2026-10-28 17:56:50 +08:00
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
31 lines
650 B
PHP
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"/>
|