From:             mail_ben_schmidt at yahoo dot com dot au
Operating system: Mac OS X
PHP version:      5.2.3
PHP Bug Type:     SimpleXML related
Bug description:  Attributes set in wrong namespace, and multiply defined

Description:
------------
OK! This one really is a bug! I know it must be a bug as invalid XML is
produced that can't be parsed! I have also tried it with
php5.2-200707181030, though just running the binary in sapi/cli/php rather
than doing make install.

When attributes are set or added using array notation, this is not done
according to the currently active scope of the SimpleXMLElement in use.

Deletion and access work as expected, however. Thus a newly added/modified
attribute cannot then be deleted or accessed without changing namespaces to
the unnamed namespace by use of attributes().

Reproduce code:
---------------
$str=<<<DONE
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";>
<elem attr="abc"/>
<elem ns:attr="abc"/>
<ns:elem attr="abc"/>
<ns:elem ns:attr="abc"/>
</root>
DONE;

$xml =
simplexml_load_string($str,'SimpleXMLElement',0,'http://localhost/a');
foreach ($xml->children('http://localhost/a') as $elem) {
        unset($elem['attr']);
        $elem['attr']="new";
        $elem['attr']="three";
        echo $elem['attr']."\n";
}
echo $xml->asXML();


Expected result:
----------------
three
three
three
three
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";>
<elem attr="abc" ns:attr="three"/>
<elem ns:attr="three"/>
<ns:elem attr="abc" ns:attr="three"/>
<ns:elem ns:attr="three"/>
</root>


Actual result:
--------------
[begins with four blank lines]




<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";>
<elem attr="abc" attr="new" attr="three"/>
<elem attr="new" attr="three"/>
<ns:elem attr="abc" attr="new" attr="three"/>
<ns:elem attr="new" attr="three"/>
</root>


-- 
Edit bug report at http://bugs.php.net/?id=42083&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42083&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42083&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42083&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42083&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42083&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42083&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42083&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42083&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42083&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42083&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42083&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42083&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42083&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42083&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42083&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42083&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42083&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42083&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42083&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42083&r=mysqlcfg

Reply via email to