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:3
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-28 12:45 UTC] jani@php.net
-Package: Feature/Change Request +Package: SimpleXML related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC