|  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.
Block user comment
Status: Assign to:
Bug Type:
From: vadimx at gmail dot com
New email:
PHP Version: OS:


 [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-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 17:01:30 2024 UTC