|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44478 Unconsistent behaviour when assigning new nodes
Submitted: 2008-03-19 12:22 UTC Modified: 2008-03-20 16:53 UTC
From: vesko at webstudiobulgaria dot com Assigned:
Status: Closed Package: SimpleXML related
PHP Version: 5.2.5 OS: Debian testing
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
33 - 7 = ?
Subscribe to this entry?

 [2008-03-19 12:22 UTC] vesko at webstudiobulgaria dot com
There is a difference in the way the html entities are handled when the new nodes are assigned in different ways. In case of using addChild method they are decoded, otherwise not.

Reproduce code:
$xml_element = new simpleXMLElement('<root></root>');
$xml_element->node1 = 'a &#38; b';
$xml_element->addChild('node2','c &#38; d');

print $xml_element->node1;
print $xml_element->node2;

Expected result:
a &#38; bc &#38; d//both left
a & bc & d//both decoded

Actual result:
a &#38; bc & d//one left and the other decoded


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-19 12:53 UTC] vesko at webstudiobulgaria dot com
Based on:
$xml_element = new simpleXMLElement('<root></root>');
$xml_element['attrib1'] = 'a &#38; b';
$xml_element->addAttribute('attrib2','c &#38; d');

print $xml_element['attrib1'];
print $xml_element['attrib2'];

which gives:
a &#38; bc &#38; d

I guess the correct behaviour is to leave the entities as they are, so in the previous example addChild() gives the wring result.
 [2008-03-19 13:16 UTC] vesko at webstudiobulgaria dot com
And another one:
$xml_element->node1[0] = 'a &#38; b';

decodes the html entities while it should not.
 [2008-03-20 00:22 UTC]
Simple patch:
 [2008-03-20 09:15 UTC] vesko at webstudiobulgaria dot com
Hi Felipe,

Thanks for the patch.
I've tested it against 5.2.5 source. It fixes the case:

$xml_element->addChild('node2','c &#38; d');

but not the case:

$xml_element->node1[0] = 'a &#38; b';//still decodes
 [2008-03-20 11:54 UTC]
Oh, really. I've updated the patch. :)
 [2008-03-20 12:40 UTC] vesko at webstudiobulgaria dot com
It is fixed now.
I hope the patch will be included in the upcoming 5.2.6 :)
 [2008-03-20 16:53 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

While the direct assignment problem was a bug, the addChild() case works 
as expected. It allows fine grained control over adding content in 
SimpleXML, including setting pre-escaped data.
 [2011-12-05 12:30 UTC] quamis at gmail dot com
This problem is still present in PHP 5.3.6-13ubuntu3.2 with Suhosin-Patch
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 21:01:27 2024 UTC