|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39866 simpleXMLElement == behaviur changed
Submitted: 2006-12-18 13:22 UTC Modified: 2006-12-18 21:50 UTC
From: liatb at marvell dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.0 OS: windows
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:
44 - 20 = ?
Subscribe to this entry?

 [2006-12-18 13:22 UTC] liatb at marvell dot com
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:

$xmlStr = "<test id=\"5\"><name>hello</name></test>";

$xml_1 = simplexml_load_string($xmlStr);

$xml_2 = simplexml_load_string($xmlStr);



if($xml_1['id'] == $xml_2['id']) {
    print("equal ids");
    print("not equal ids");

if($xml_1->name == $xml_2->name)
    print("equal names");
    print("not equal names");


Expected result:
equal ids
equal names

Actual result:
not equal ids
not equal names


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-18 13:58 UTC]
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
 [2006-12-18 21:50 UTC] liatb at marvell dot com
I was comparing two objects and not object two string. I followed the description in "Comparing objects" in the manual
As it worked as I expected in 5.0 and 5.1 I expected it to keep the same output in 5.2
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Jun 07 15:03:42 2023 UTC