Bug #52553 [Com]: the result is different between php versions
| From: | info at nection dot io | Date: | Thu, 16 Sep 2021 14:56:10 +0000 |
| Subject: | Bug #52553 [Com]: the result is different between php versions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236648@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52553&edit=1
ID: 52553
Comment by: info at nection dot io
Reported by: dataget2001 at yahoo dot co dot jp
Summary: the result is different between php versions
Status: Not a bug
Type: Bug
Package: SimpleXML related
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
I had the same bug when we developing our https://nection.io
product.
Previous Comments:
------------------------------------------------------------------------
[2015-05-22 02:40:06] cmb@php.net
> the result of test script below is different between php version
> 5.1.6 and version 5.3.2.
That is because the relevant bug has been fixed in PHP 5.2.6[1].
You don't have to escape HTML entities (actually, you should not)
when assigning to a node; that is supposed to be done by
SimpleXML[2].
[1] <http://3v4l.org/vv8CB>
[2] <http://3v4l.org/U1tvv>
------------------------------------------------------------------------
[2010-09-11 19:02:17] felipe@php.net
The bug related to this stuff is the bug #44478
According to the test committed for the mentioned bug
(http://svn.php.net/viewvc/php/php-src/trunk/ext/simplexml/tests/bug44478.phpt?revision=255607&view=markup)
it seems expected.
To get the expected behavior, use addChild().
<?php
$xml_element = new simpleXMLElement('<root></root>');
$xml_element->addchild('node1', 'a & b');
var_dump($xml_element->node1);
/*
object(SimpleXMLElement)#2 (1) {
[0]=>
string(5) "a & b"
}
*/
------------------------------------------------------------------------
[2010-09-11 18:11:30] felipe@php.net
This report remember another report. Need to find it.
------------------------------------------------------------------------
[2010-08-06 10:43:48] dataget2001 at yahoo dot co dot jp
Description:
------------
the result of test script below is different between php version 5.1.6 and version 5.3.2.
Test script:
---------------
<?php
var_dump(phpversion());
$foo1 = new SimpleXMLElement('<?xml version="1.0"
encoding="UTF-8"?><root />');
$foo1->addChild("x", htmlspecialchars("<test />"));
$foo2 = new SimpleXMLElement('<?xml version="1.0"
encoding="UTF-8"?><root><x /></root>');
$foo2->x = htmlspecialchars("<test />");
var_dump($foo1->x);
var_dump($foo2->x);
var_dump($foo1->asXML() === $foo2->asXML());
?>
Expected result:
----------------
string(5) "5.1.6"
object(SimpleXMLElement)#3 (1) {
[0]=>
string(8) "<test />"
}
object(SimpleXMLElement)#3 (1) {
[0]=>
string(8) "<test />"
}
bool(true)
Actual result:
--------------
string(5) "5.3.2"
object(SimpleXMLElement)#3 (1) {
[0]=>
string(8) "<test />"
}
object(SimpleXMLElement)#3 (1) {
[0]=>
string(14) "<test />"
}
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52553&edit=1