|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-12-28 12:45 UTC] jani@php.net
-Package: Feature/Change Request
+Package: SimpleXML related
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 00:00:02 2025 UTC |
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>