From: gf at glbasic dot com
Operating system: Debian
PHP version: 5.2.11
PHP Bug Type: Feature/Change Request
Bug description: SimpleXML can't change value of reference
Description:
------------
If you have a reference to an SimpleXML subtree item, you cannot change
the value of that.
Reproduce code:
---------------
<?php
$xml = new SimpleXMLElement("<?xml version='1.0'?>\n"
."<chunk>\n"
."<item
id='1'>one</item>\n"
."<item
id='2'>two</item>\n"
."</chunk>\n"
);
function test(& $xentry)
{
$xentry['id'] = 22; // set id=2 to id=22, works fine
$xentry = 'TWENTYTWO'; // !!! this line is ignored !!!
}
$xml->item[0] = 'ELEVEN'; // works
$xml->item[0]['id']=11; // works
echo str_replace("\n", "<br>", htmlspecialchars($xml->asXML()))."<br>"; //
OK, fine
// try the same with a reference -> does not work
test($xml->item[1]);
echo "<h3>After replacement:</h2>";
echo str_replace("\n", "<br>", htmlspecialchars($xml->asXML())); // error
- $xentry is not an object
?>
Expected result:
----------------
...
<item id="2">two</item>
After replacement:
...
<item id="22">TWENTYTWO</item>
Actual result:
--------------
...
<item id="2">two</item>
After replacement:
...
<item id="22">two</item>
--
Edit bug report at http://bugs.php.net/?id=49942&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49942&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49942&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49942&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49942&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=49942&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49942&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=49942&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=49942&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=49942&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=49942&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=49942&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=49942&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=49942&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49942&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49942&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49942&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=49942&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=49942&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=49942&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=49942&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=49942&r=mysqlcfg