Ask a Question related to PHP Bugs, Design and Development.
-
hans at velum dot net #1
#40691 [NEW]: Incorrect results of DateTime equality check
From: hans at velum dot net
Operating system: Gentoo Linux
PHP version: 5.2.1
PHP Bug Type: Date/time related
Bug description: Incorrect results of DateTime equality check
Description:
------------
The equality check (==) for DateTime objects does not actually check the
properties of the object (i.e. the internally stored date). This is very
counter-intuitive as it does not follow the behavior of user-created
objects or even other internal PHP objects like Exception.
Reproduce code:
---------------
$d1 = new DateTime("2001-01-01");
$d2 = new DateTime("2007-02-28");
print "DateTime Equal? " . var_export($d1 == $d2, true) . "\n";
Expected result:
----------------
DateTime Equal? false
Actual result:
--------------
DateTime Equal? true
--
Edit bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
--
Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40691&r=trysnapshot44[/url]
Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40691&r=trysnapshot52[/url]
Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40691&r=trysnapshot60[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40691&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=40691&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=40691&r=needtrace[/url]
Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40691&r=needscript[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=40691&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=40691&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=40691&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=40691&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=40691&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=40691&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40691&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=40691&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=40691&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40691&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=40691&r=float[/url]
No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40691&r=nozend[/url]
MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40691&r=mysqlcfg[/url]
hans at velum dot net Guest
-
#39782 [NEW]: setTime() on a DateTime constructed with a Weekday yields incorrect results
From: php at michaelho dot com Operating system: Max OS X 10.4.7 PHP version: 5.2.0 PHP Bug Type: Date/time related Bug... -
Incorrect results on DB2 UDB v7.2
Anyone recognised the following bug (is there an APAR)? Incorrect results can be returned when using IN lists of string literals and then... -
Re Incorrect results on DB2 UDB v7.2
Further to previous post , please ignore - the following fixpak 8 APAR (originally for AIX) looks near-identical, certainly worth a shot: ... -
#24891 [Bgs]: Decimal equality incorrect result
ID: 24891 User updated by: jeff at tmtrading dot com Reported By: jeff at tmtrading dot com Status: Bogus Bug Type:... -
#24891 [Opn->Bgs]: Decimal equality incorrect result
ID: 24891 Updated by: sniper@php.net Reported By: jeff at tmtrading dot com -Status: Open +Status: ... -
iliaa@php.net #2
#40691 [Opn->Bgs]: Incorrect results of DateTime equality check
ID: 40691
Updated by: [email]iliaa@php.net[/email]
Reported By: hans at velum dot net
-Status: Open
+Status: Bogus
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
Read on object comparison in PHP, what you are attempting will not
work.
if you want to compare 2 dates, convert them to unix timestamps first.
Previous Comments:
------------------------------------------------------------------------
[2007-03-02 15:43:14] hans at velum dot net
Description:
------------
The equality check (==) for DateTime objects does not actually check
the properties of the object (i.e. the internally stored date). This
is very counter-intuitive as it does not follow the behavior of
user-created objects or even other internal PHP objects like Exception.
Reproduce code:
---------------
$d1 = new DateTime("2001-01-01");
$d2 = new DateTime("2007-02-28");
print "DateTime Equal? " . var_export($d1 == $d2, true) . "\n";
Expected result:
----------------
DateTime Equal? false
Actual result:
--------------
DateTime Equal? true
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
iliaa@php.net Guest
-
hans at velum dot net #3
#40691 [Bgs->Opn]: Incorrect results of DateTime equality check
ID: 40691
User updated by: hans at velum dot net
Reported By: hans at velum dot net
-Status: Bogus
+Status: Open
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
New Comment:
This is not bogus. Maybe "won't fix" but definitely not bogus.
Please note that I am quite familiar with object comparison in PHP. The
documenation says: "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."
Indeed, AS I POINTED OUT IN THE DESCRIPTION, other built-in objects in
PHP demonstrate the correct/expected behavior:
$a = new Exception("foo");
$b = new Exception("bar");
$c = new Exception("foo");
var_export($a == $b); // Outputs: FALSE
var_export($a == $c); // Outputs: TRUE
A DateTime object have very obvious properties (namely the date/time
value contained, possibly time zone of other info specified). The
equality check (NOT IDENTITY CHECK) should be comparing those values,
as apparently it does for Exception.
Previous Comments:
------------------------------------------------------------------------
[2007-03-03 15:55:40] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
Read on object comparison in PHP, what you are attempting will not
work.
if you want to compare 2 dates, convert them to unix timestamps first.
------------------------------------------------------------------------
[2007-03-02 15:43:14] hans at velum dot net
Description:
------------
The equality check (==) for DateTime objects does not actually check
the properties of the object (i.e. the internally stored date). This
is very counter-intuitive as it does not follow the behavior of
user-created objects or even other internal PHP objects like Exception.
Reproduce code:
---------------
$d1 = new DateTime("2001-01-01");
$d2 = new DateTime("2007-02-28");
print "DateTime Equal? " . var_export($d1 == $d2, true) . "\n";
Expected result:
----------------
DateTime Equal? false
Actual result:
--------------
DateTime Equal? true
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
hans at velum dot net Guest
-
dzuelke at gmail dot com #4
#40691 [Com]: Incorrect results of DateTime equality check
ID: 40691
Comment by: dzuelke at gmail dot com
Reported By: hans at velum dot net
Status: Open
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
New Comment:
hans at velum dot net is correct, I just stumbled over the same issue.
It definitely smells like a bug, nothing bogus here. The stored date is
a property of the object, but not compared properly as it should
according to the rules described at [url]http://php.net/manual/en/[/url]
language.oop5.php. Probably because it's not possible to pull the
individual parts of a date (day, month, year etc) from a DateTime
instance, but that's a different story...
Previous Comments:
------------------------------------------------------------------------
[2007-03-03 19:47:15] hans at velum dot net
This is not bogus. Maybe "won't fix" but definitely not bogus.
Please note that I am quite familiar with object comparison in PHP. The
documenation says: "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."
Indeed, AS I POINTED OUT IN THE DESCRIPTION, other built-in objects in
PHP demonstrate the correct/expected behavior:
$a = new Exception("foo");
$b = new Exception("bar");
$c = new Exception("foo");
var_export($a == $b); // Outputs: FALSE
var_export($a == $c); // Outputs: TRUE
A DateTime object have very obvious properties (namely the date/time
value contained, possibly time zone of other info specified). The
equality check (NOT IDENTITY CHECK) should be comparing those values,
as apparently it does for Exception.
------------------------------------------------------------------------
[2007-03-03 15:55:40] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
Read on object comparison in PHP, what you are attempting will not
work.
if you want to compare 2 dates, convert them to unix timestamps first.
------------------------------------------------------------------------
[2007-03-02 15:43:14] hans at velum dot net
Description:
------------
The equality check (==) for DateTime objects does not actually check
the properties of the object (i.e. the internally stored date). This
is very counter-intuitive as it does not follow the behavior of
user-created objects or even other internal PHP objects like Exception.
Reproduce code:
---------------
$d1 = new DateTime("2001-01-01");
$d2 = new DateTime("2007-02-28");
print "DateTime Equal? " . var_export($d1 == $d2, true) . "\n";
Expected result:
----------------
DateTime Equal? false
Actual result:
--------------
DateTime Equal? true
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
dzuelke at gmail dot com Guest
-
iliaa@php.net #5
#40691 [Opn->Bgs]: Incorrect results of DateTime equality check
ID: 40691
Updated by: [email]iliaa@php.net[/email]
Reported By: hans at velum dot net
-Status: Open
+Status: Bogus
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
This is not a bug. The date extension does not provide (or is intended)
for the purpose of comparing two date objects. You could have the same
date in the object by different properties initialized due to the way
the object was created.
As I've said earlier the most reliable way to compare two dates would
be
to convert them to unix timestamps and then compare the two.
Previous Comments:
------------------------------------------------------------------------
[2007-03-03 21:36:07] dzuelke at gmail dot com
hans at velum dot net is correct, I just stumbled over the same issue.
It definitely smells like a bug, nothing bogus here. The stored date is
a property of the object, but not compared properly as it should
according to the rules described at [url]http://php.net/manual/en/[/url]
language.oop5.php. Probably because it's not possible to pull the
individual parts of a date (day, month, year etc) from a DateTime
instance, but that's a different story...
------------------------------------------------------------------------
[2007-03-03 19:47:15] hans at velum dot net
This is not bogus. Maybe "won't fix" but definitely not bogus.
Please note that I am quite familiar with object comparison in PHP. The
documenation says: "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."
Indeed, AS I POINTED OUT IN THE DESCRIPTION, other built-in objects in
PHP demonstrate the correct/expected behavior:
$a = new Exception("foo");
$b = new Exception("bar");
$c = new Exception("foo");
var_export($a == $b); // Outputs: FALSE
var_export($a == $c); // Outputs: TRUE
A DateTime object have very obvious properties (namely the date/time
value contained, possibly time zone of other info specified). The
equality check (NOT IDENTITY CHECK) should be comparing those values,
as apparently it does for Exception.
------------------------------------------------------------------------
[2007-03-03 15:55:40] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
Read on object comparison in PHP, what you are attempting will not
work.
if you want to compare 2 dates, convert them to unix timestamps first.
------------------------------------------------------------------------
[2007-03-02 15:43:14] hans at velum dot net
Description:
------------
The equality check (==) for DateTime objects does not actually check
the properties of the object (i.e. the internally stored date). This
is very counter-intuitive as it does not follow the behavior of
user-created objects or even other internal PHP objects like Exception.
Reproduce code:
---------------
$d1 = new DateTime("2001-01-01");
$d2 = new DateTime("2007-02-28");
print "DateTime Equal? " . var_export($d1 == $d2, true) . "\n";
Expected result:
----------------
DateTime Equal? false
Actual result:
--------------
DateTime Equal? true
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
iliaa@php.net Guest
-
hans at velum dot net #6
#40691 [Bgs->Opn]: Incorrect results of DateTime equality check
ID: 40691
User updated by: hans at velum dot net
Reported By: hans at velum dot net
-Status: Bogus
+Status: Open
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
New Comment:
I maintain that this is counter-intuitive behavior. Do any other
built-in classes have this same comparison "feature" where they always
return TRUE when checked for eqaulity? If you truly believe this is
bogus, then this is a problem that must be addressed in the
documenation (which incidentally is basically horrible for the DateTime
class). It is simply not acceptable behavior to have a == comparison
between ANY DateTime object return TRUE.
This type of inconsistent & incoherent behavior in the PHP core is why
PHP maintains a poor reputation for OO development. It would be a huge
help to the community if these core classes worked in a predictable
manner, or at *least* if their unpredictable behavior were addressed by
documentation.
Previous Comments:
------------------------------------------------------------------------
[2007-03-04 18:34:12] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
This is not a bug. The date extension does not provide (or is intended)
for the purpose of comparing two date objects. You could have the same
date in the object by different properties initialized due to the way
the object was created.
As I've said earlier the most reliable way to compare two dates would
be
to convert them to unix timestamps and then compare the two.
------------------------------------------------------------------------
[2007-03-03 21:36:07] dzuelke at gmail dot com
hans at velum dot net is correct, I just stumbled over the same issue.
It definitely smells like a bug, nothing bogus here. The stored date is
a property of the object, but not compared properly as it should
according to the rules described at [url]http://php.net/manual/en/[/url]
language.oop5.php. Probably because it's not possible to pull the
individual parts of a date (day, month, year etc) from a DateTime
instance, but that's a different story...
------------------------------------------------------------------------
[2007-03-03 19:47:15] hans at velum dot net
This is not bogus. Maybe "won't fix" but definitely not bogus.
Please note that I am quite familiar with object comparison in PHP. The
documenation says: "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."
Indeed, AS I POINTED OUT IN THE DESCRIPTION, other built-in objects in
PHP demonstrate the correct/expected behavior:
$a = new Exception("foo");
$b = new Exception("bar");
$c = new Exception("foo");
var_export($a == $b); // Outputs: FALSE
var_export($a == $c); // Outputs: TRUE
A DateTime object have very obvious properties (namely the date/time
value contained, possibly time zone of other info specified). The
equality check (NOT IDENTITY CHECK) should be comparing those values,
as apparently it does for Exception.
------------------------------------------------------------------------
[2007-03-03 15:55:40] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
Read on object comparison in PHP, what you are attempting will not
work.
if you want to compare 2 dates, convert them to unix timestamps first.
------------------------------------------------------------------------
[2007-03-02 15:43:14] hans at velum dot net
Description:
------------
The equality check (==) for DateTime objects does not actually check
the properties of the object (i.e. the internally stored date). This
is very counter-intuitive as it does not follow the behavior of
user-created objects or even other internal PHP objects like Exception.
Reproduce code:
---------------
$d1 = new DateTime("2001-01-01");
$d2 = new DateTime("2007-02-28");
print "DateTime Equal? " . var_export($d1 == $d2, true) . "\n";
Expected result:
----------------
DateTime Equal? false
Actual result:
--------------
DateTime Equal? true
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
hans at velum dot net Guest
-
derick@php.net #7
#40691 [Opn->Asn]: Incorrect results of DateTime equality check
ID: 40691
Updated by: [email]derick@php.net[/email]
Reported By: hans at velum dot net
-Status: Open
+Status: Assigned
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
-Assigned To:
+Assigned To: derick
New Comment:
I am not sure it is even possible to overload the == operator here, but
I can check that. However, the comparison of unix timestamps is still
the way to go for now.
Previous Comments:
------------------------------------------------------------------------
[2007-03-04 20:40:49] hans at velum dot net
I maintain that this is counter-intuitive behavior. Do any other
built-in classes have this same comparison "feature" where they always
return TRUE when checked for eqaulity? If you truly believe this is
bogus, then this is a problem that must be addressed in the
documenation (which incidentally is basically horrible for the DateTime
class). It is simply not acceptable behavior to have a == comparison
between ANY DateTime object return TRUE.
This type of inconsistent & incoherent behavior in the PHP core is why
PHP maintains a poor reputation for OO development. It would be a huge
help to the community if these core classes worked in a predictable
manner, or at *least* if their unpredictable behavior were addressed by
documentation.
------------------------------------------------------------------------
[2007-03-04 18:34:12] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
This is not a bug. The date extension does not provide (or is intended)
for the purpose of comparing two date objects. You could have the same
date in the object by different properties initialized due to the way
the object was created.
As I've said earlier the most reliable way to compare two dates would
be
to convert them to unix timestamps and then compare the two.
------------------------------------------------------------------------
[2007-03-03 21:36:07] dzuelke at gmail dot com
hans at velum dot net is correct, I just stumbled over the same issue.
It definitely smells like a bug, nothing bogus here. The stored date is
a property of the object, but not compared properly as it should
according to the rules described at [url]http://php.net/manual/en/[/url]
language.oop5.php. Probably because it's not possible to pull the
individual parts of a date (day, month, year etc) from a DateTime
instance, but that's a different story...
------------------------------------------------------------------------
[2007-03-03 19:47:15] hans at velum dot net
This is not bogus. Maybe "won't fix" but definitely not bogus.
Please note that I am quite familiar with object comparison in PHP. The
documenation says: "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."
Indeed, AS I POINTED OUT IN THE DESCRIPTION, other built-in objects in
PHP demonstrate the correct/expected behavior:
$a = new Exception("foo");
$b = new Exception("bar");
$c = new Exception("foo");
var_export($a == $b); // Outputs: FALSE
var_export($a == $c); // Outputs: TRUE
A DateTime object have very obvious properties (namely the date/time
value contained, possibly time zone of other info specified). The
equality check (NOT IDENTITY CHECK) should be comparing those values,
as apparently it does for Exception.
------------------------------------------------------------------------
[2007-03-03 15:55:40] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
Read on object comparison in PHP, what you are attempting will not
work.
if you want to compare 2 dates, convert them to unix timestamps first.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
[url]http://bugs.php.net/40691[/url]
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
derick@php.net Guest
-
hans at velum dot net #8
#40691 [Asn]: Incorrect results of DateTime equality check
ID: 40691
User updated by: hans at velum dot net
Reported By: hans at velum dot net
Status: Assigned
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
Assigned To: derick
New Comment:
Thanks, Derick!
Previous Comments:
------------------------------------------------------------------------
[2007-03-05 09:59:48] [email]derick@php.net[/email]
I am not sure it is even possible to overload the == operator here, but
I can check that. However, the comparison of unix timestamps is still
the way to go for now.
------------------------------------------------------------------------
[2007-03-04 20:40:49] hans at velum dot net
I maintain that this is counter-intuitive behavior. Do any other
built-in classes have this same comparison "feature" where they always
return TRUE when checked for eqaulity? If you truly believe this is
bogus, then this is a problem that must be addressed in the
documenation (which incidentally is basically horrible for the DateTime
class). It is simply not acceptable behavior to have a == comparison
between ANY DateTime object return TRUE.
This type of inconsistent & incoherent behavior in the PHP core is why
PHP maintains a poor reputation for OO development. It would be a huge
help to the community if these core classes worked in a predictable
manner, or at *least* if their unpredictable behavior were addressed by
documentation.
------------------------------------------------------------------------
[2007-03-04 18:34:12] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
This is not a bug. The date extension does not provide (or is intended)
for the purpose of comparing two date objects. You could have the same
date in the object by different properties initialized due to the way
the object was created.
As I've said earlier the most reliable way to compare two dates would
be
to convert them to unix timestamps and then compare the two.
------------------------------------------------------------------------
[2007-03-03 21:36:07] dzuelke at gmail dot com
hans at velum dot net is correct, I just stumbled over the same issue.
It definitely smells like a bug, nothing bogus here. The stored date is
a property of the object, but not compared properly as it should
according to the rules described at [url]http://php.net/manual/en/[/url]
language.oop5.php. Probably because it's not possible to pull the
individual parts of a date (day, month, year etc) from a DateTime
instance, but that's a different story...
------------------------------------------------------------------------
[2007-03-03 19:47:15] hans at velum dot net
This is not bogus. Maybe "won't fix" but definitely not bogus.
Please note that I am quite familiar with object comparison in PHP. The
documenation says: "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."
Indeed, AS I POINTED OUT IN THE DESCRIPTION, other built-in objects in
PHP demonstrate the correct/expected behavior:
$a = new Exception("foo");
$b = new Exception("bar");
$c = new Exception("foo");
var_export($a == $b); // Outputs: FALSE
var_export($a == $c); // Outputs: TRUE
A DateTime object have very obvious properties (namely the date/time
value contained, possibly time zone of other info specified). The
equality check (NOT IDENTITY CHECK) should be comparing those values,
as apparently it does for Exception.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
[url]http://bugs.php.net/40691[/url]
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
hans at velum dot net Guest
-
mike@php.net #9
#40691 [Asn->Csd]: Incorrect results of DateTime equality check
ID: 40691
Updated by: [email]mike@php.net[/email]
Reported By: hans at velum dot net
-Status: Assigned
+Status: Closed
Bug Type: Date/time related
Operating System: Gentoo Linux
PHP Version: 5.2.1
Assigned To: derick
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
[url]http://snaps.php.net/[/url].
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2007-03-05 12:04:02] hans at velum dot net
Thanks, Derick!
------------------------------------------------------------------------
[2007-03-05 09:59:48] [email]derick@php.net[/email]
I am not sure it is even possible to overload the == operator here, but
I can check that. However, the comparison of unix timestamps is still
the way to go for now.
------------------------------------------------------------------------
[2007-03-04 20:40:49] hans at velum dot net
I maintain that this is counter-intuitive behavior. Do any other
built-in classes have this same comparison "feature" where they always
return TRUE when checked for eqaulity? If you truly believe this is
bogus, then this is a problem that must be addressed in the
documenation (which incidentally is basically horrible for the DateTime
class). It is simply not acceptable behavior to have a == comparison
between ANY DateTime object return TRUE.
This type of inconsistent & incoherent behavior in the PHP core is why
PHP maintains a poor reputation for OO development. It would be a huge
help to the community if these core classes worked in a predictable
manner, or at *least* if their unpredictable behavior were addressed by
documentation.
------------------------------------------------------------------------
[2007-03-04 18:34:12] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
This is not a bug. The date extension does not provide (or is intended)
for the purpose of comparing two date objects. You could have the same
date in the object by different properties initialized due to the way
the object was created.
As I've said earlier the most reliable way to compare two dates would
be
to convert them to unix timestamps and then compare the two.
------------------------------------------------------------------------
[2007-03-03 21:36:07] dzuelke at gmail dot com
hans at velum dot net is correct, I just stumbled over the same issue.
It definitely smells like a bug, nothing bogus here. The stored date is
a property of the object, but not compared properly as it should
according to the rules described at [url]http://php.net/manual/en/[/url]
language.oop5.php. Probably because it's not possible to pull the
individual parts of a date (day, month, year etc) from a DateTime
instance, but that's a different story...
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
[url]http://bugs.php.net/40691[/url]
--
Edit this bug report at [url]http://bugs.php.net/?id=40691&edit=1[/url]
mike@php.net Guest



Reply With Quote

