#39866 [Bgs]: simpleXMLElement == behaviur changed
| From: | liatb at marvell dot com | Date: | Mon, 18 Dec 2006 21:50:13 +0000 |
| Subject: | #39866 [Bgs]: simpleXMLElement == behaviur changed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-106524@lists.php.net to get a copy of this message | ||
ID: 39866
User updated by: liatb at marvell dot com
Reported By: liatb at marvell dot com
Status: Bogus
Bug Type: SimpleXML related
Operating System: windows
PHP Version: 5.2.0
New Comment:
I was comparing two objects and not object two string. I followed the
description in "Comparing objects" in the manual
http://www.php.net/manual/en/language.oop5.object-comparison.php
As it worked as I expected in 5.0 and 5.1 I expected it to keep the
same output in 5.2
Previous Comments:
------------------------------------------------------------------------
[2006-12-18 13:58:00] tony2001@php.net
That's right. Object are equal only if they point to the same libxml2
data.
You must cast the objects to strings first if you want to compare them
as strings.
See "Example 5" at http://php.net/simplexml.
------------------------------------------------------------------------
[2006-12-18 13:22:03] liatb at marvell dot com
Description:
------------
I upgraded my PHP version from 5.1.* to 5.2.0
XML string loaded into two different simpleXML objects.
The result of comparing xml node attributes (without any specific cast)
in version 5.2.0 is different then used to be in 5.0.3 and 5.1.5.
I also checked the last snapshot for windows marked as "PHP Version
5.2.1RC2-dev" and got the same output as 5.2.0
Reproduce code:
---------------
<?php
$xmlStr = "<test id=\"5\"><name>hello</name></test>";
$xml_1 = simplexml_load_string($xmlStr);
$xml_2 = simplexml_load_string($xmlStr);
var_dump($xml_1);
var_dump($xml_2);
print("<br/>");
if($xml_1['id'] == $xml_2['id']) {
print("equal ids");
}
else
{
print("not equal ids");
}
print("<br/>");
if($xml_1->name == $xml_2->name)
{
print("equal names");
}
else
{
print("not equal names");
}
?>
Expected result:
----------------
equal ids
equal names
Actual result:
--------------
not equal ids
not equal names
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39866&edit=1