php.net |  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
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gf at glbasic dot com
New email:
PHP Version: OS:

 

 [2009-10-21 12:29 UTC] gf at glbasic dot com
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>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-28 12:45 UTC] jani@php.net
-Package: Feature/Change Request +Package: SimpleXML related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Nov 17 23:01:36 2019 UTC