|  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
 [2012-11-22 16:40 UTC] vadimx at gmail dot com
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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-23 01:52 UTC]
-Status: Open +Status: Not a bug
 [2012-11-23 01:52 UTC]
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-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 03:03:42 2022 UTC