Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6829295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:29:01+00:00 2026-05-26T22:29:01+00:00

As tested with phpunit: $xml_1 = new SimpleXMLElement(‘<name>Bugs</name>’); $xml_2 = new SimpleXMLElement(‘<name>Bugs</name>’); $this->assertEquals($xml_1, $xml_2);

  • 0

As tested with phpunit:

$xml_1 = new SimpleXMLElement('<name>Bugs</name>');
$xml_2 = new SimpleXMLElement('<name>Bugs</name>');

$this->assertEquals($xml_1, $xml_2);    // Passes
$this->assertTrue($xml_1==$xml_2);      // Fails

Um, what?

EDIT:
No, this is not a stupid question. In Python:

import unittest
class TestEqualityIdentity(unittest.TestCase):
def test_equality(self):
    x   =   1
    y   =   1
    self.assertTrue(x==y)       # Passes
    self.assertEqual(x, y)      # Passes
if __name__ == '__main__':
    unittest.main()

No reason PHP need behave like Python. But, it isn’t a stupid question in PHP either.

$x = 1;
$y = 1;
$this->assertEquals($x, $y);        //  Passes
$this->assertTrue($x==$y);          //  Passes

EDIT 2
Raymond’s answer below is right, never mind that at this writing it’s 3 votes down.

FWIW, I needed an if test comparison of the text node values of two XML objects, and got it by casting them to strings.

$this->assertTrue((string) $xml_1== (string) $xml_2); // Passes, works in if test

// Note that simply referring to a SimpleXMLElement _seems_ to give its 
// text node.  

$this->assertEquals($xml_1, 'Bugs');  // Passes

// This seemed weird to me when I first saw it, and I can't 
// say I like it any better now
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:29:02+00:00Added an answer on May 26, 2026 at 10:29 pm

    +1 This is a great question.

    I had to look in the PHP docs for the answers: http://www.phpunit.de/manual/3.4/en/api.html

    Equality isn’t defined for XML Element objects, so the $this->assertTrue($xml_1==$xml_2); will only succeed if the two objects have the same identity (are the same object).

    In contrast, assertEquals tries to be smart and has special case handling depending on object type. In the case of XML, it compares the structure and contents of the XML elements, returning True if they have the same semantic meaning eventhough they are distinct objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tested this servlet and it works well, except in Google Chrome it
I tested this script on another server and it worked fine. Do I have
Tested this both on Ubuntu and ArchLinux, I get from ctypes import * libc
I tested this query in my database, and it works fine: select * from
I tested this block of code and find that the GetInts method does not
I tested this expression in gdb: (gdb) p (int)[@-1 floatValue] $2 = 1 but
I just tested this simple php file upload script. Works in all browsers except
I have tested this on Firefox, Opera and Seamonkey. It works fine. When it
PhpUnit::How can be __construct with protected variables tested? (not always we should add public
I tested my site with the new IE 9 and I get the error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.