ID:               44411
 Comment by:       hubert dot roksor at gmail dot com
 Reported By:      phpbugs at steve dot ipapp dot com
 Status:           Open
 Bug Type:         SimpleXML related
 Operating System: ANY
 PHP Version:      5.2.5
 New Comment:

As per the manual chapter you quoted, the comparison operator compares
_objects_, and that's the key word here. You expect two equal XML trees
to be represented by two equal objects, and even though this expectation
is understandable, it is simply not the case. Those objects are
different. In fact, even if $sax1->value is equal to $sax1->value and
they come from the same tree, they are not identical. ($sax1->value !==
$sax1->value)

The bottom line is the comparison operator compares objects. If you
need an operator that understands the underlying data you will have to
use another mean. The solution proposed in the other bug report (compare
them as XML strings) sounds reasonable.

It would be nice to mention this quirk in the manual though, perhaps as
a new example? "Comparing Elements and Elements"


Previous Comments:
------------------------------------------------------------------------

[2008-03-12 01:35:37] phpbugs at steve dot ipapp dot com

Description:
------------
In PHP 5.0.x and 5.1.x two SimpleXMLElement objects were considered
equal if they represented the same data.

In PHP 5.2.x this does not seem to be the case anymore. This was
previously listed as bug 39866 [http://bugs.php.net/bug.php?id=39866],
but for some reason this was listed as bogus.  In that bug it was noted
that we should look at Example 5 at http://php.net/simplexml. I'm
assuming this is Example 6 now [Comparing Elements and Attributes with
Text] , but this is incorrect as comparision will implicity cast 
it to string anyway.

According to
http://www.php.net/manual/en/language.oop5.object-comparison.php:
"When using the comparison operator (==), object variables are compared
in a simple manner, namely: Two object instances are equal if they have
the same attributes and values, and are instances of the same class...
On the other hand, when using the identity operator (===), object
variables are identical if and only if they refer to the same instance
of the same class." 

Furthermore this backwards incompatible change is not listed in :
http://us.php.net/manual/en/migration52.incompatible.php.

Currently there is no equals method that we can call to get the
previous functionality back, and at the present moment this makes == no
longer transitive as  especially since this makes == no longer
transitive as 'doc' == x1, 'doc' == x2, but x1 != x2. 

I do not understand why ==, nor do I see value in, doing a strict
comparison for SimpleXMLObjects as ==, when according to the PHP Object
Comparison manual this should be ===. 

Therefore I believe this is a bug.




Reproduce code:
---------------
$xmldoc = "<xml><value>foo</value></xml>";

$sax1 = new SimpleXMLElement("$xmldoc");
$sax2 = new SimpleXMLElement("$xmldoc");

if($sax1 == $sax2)
{
        echo "TRUE";
} else
{
        echo "FALSE";
}
echo "\n\n\n";


Expected result:
----------------
TRUE

Actual result:
--------------
FALSE


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44411&edit=1

Reply via email to