It would be interesting to know what other internal classes falsely
pass this non-identity comparison.
Then two new documentation entities could be used to say that
non-identity comparison is or is not possible with this class.
In my installation, I have 95 built in classes (with no extensions
added), or 106 with the extensions I use normally. I managed to get
upto 198 built in classes (by adding ALL the extensions I could get
working).
I suppose the step after this would be to make the built in classes
operate so that non-identity comparison operated based upon the USER's
perception of what should happen.
On 04/03/07, Hans Lellelid <hlellelid@php.net> wrote:
> Hi all,
>
> DateTime equality (not identity) appears to be broken. I've created a
> ticket for this issue (http://bugs.php.net/bug.php?id=40691), which
> keeps getting marked as bogus by Ilia. This may be a more appropriate
> issue to raise on list, as I seem to be having both a very hard time
> making my point about the inconsistency of the behavior and a very hard
> time being convinced that this is not a bug (at *least* a documentation
> problem, if nothing else) :)
>
> The basic problem is that a [non-identity] comparison (==) of *any*
> DateTime object with any other DateTime object will return TRUE. Now, I
> admit that I know little about the underlying layer, but as a developer
> the DateTime object has a very clear set of properties (namely
> date/time, maybe time zone) that I would expect would be compared by a
> == equality check.
>
> $d1 = new DateTime("2001-01-01");
> $d2 = new DateTime("2007-02-28");
> var_export($d1 == $d2); // Ouputs: TRUE
>
>
> This always-return-TRUE behavior is extremely counter-intuitive. It
> also appears to be very exceptional in the PHP core classes.
> Admittedly, I haven't looked through SPL, but the Exception object
> provides a perfect example for what I would expect (based on the text in
> the PHP manual about object comparison):
>
> $a = new Exception("foo");
> $b = new Exception("bar");
> $c = new Exception("foo");
>
> var_export($a == $b); // Outputs: FALSE
> var_export($a == $c); // Outputs: TRUE
>
> Obviously stdClass and user-defined classes exhibit this same behavior
> of testing the object properties -- just as I'd expect from the
> description in the manual.
>
> Is this DateTime comparison behavior actually intended to be different
> from everything else? If there's some reason that DateTime object
> properties cannot be compared to each other, wouldn't it be more
> appropriate for them to always return FALSE ?
>
> Thanks,
> Hans
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"