php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: liatb at marvell dot com
New email:
PHP Version: OS:

 

 [2006-12-18 13:22 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-18 13:58 UTC] 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 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 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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC