php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63583 Comparing objects is wrong
Submitted: 2012-11-22 16:40 UTC Modified: 2012-11-23 08:56 UTC
From: vadimx at gmail dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.3.18 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vadimx at gmail dot com
New email:
PHP Version: OS:

 

 [2012-11-22 16:40 UTC] vadimx at gmail dot com
Description:
------------
Comparing objects always returns false. How can i compare objects?

Test script:
---------------
$xml = '<a><b/></a>';

$a = new SimpleXMLElement($xml);
$b = new SimpleXMLElement($xml);

var_dump($a == $b);


Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-23 01:52 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-11-23 01:52 UTC] aharvey@php.net
SimpleXML does implement object comparison, but it compares both the underlying document and node — if they aren't the same (and they aren't, in this case, since both new SimpleXMLElement() calls create new documents and nodes), then the objects aren't the same.
 [2012-11-23 08:56 UTC] vadimx at gmail dot com
So, for compare 2 SimpleXMLElement objects, i have one, not good way 
var_dump($o1->asXML() == $o2->asXML()), but it's wrong if one space (or \n \t) 
before tag name are different?
Or exists another method, for check if 2 SimpleXMLElement objects are same?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 11:01:31 2024 UTC