|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49942 SimpleXML can't change value of reference
Submitted: 2009-10-21 12:29 UTC Modified: 2010-12-28 12:45 UTC
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: gf at glbasic dot com Assigned:
Status: Open Package: SimpleXML related
PHP Version: 5.2.11 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gf at glbasic dot com
New email:
PHP Version: OS:


 [2009-10-21 12:29 UTC] gf at glbasic dot com
If you have a reference to an SimpleXML subtree item, you cannot change the value of that.

Reproduce code:
$xml = new SimpleXMLElement("<?xml version='1.0'?>\n"
							."<item id='1'>one</item>\n"
							."<item id='2'>two</item>\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
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>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-28 12:45 UTC]
-Package: Feature/Change Request +Package: SimpleXML related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 11:01:31 2024 UTC