php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65548 Comparison for DateTimeImmutable doesn't work
Submitted: 2013-08-25 14:03 UTC Modified: -
From: mail at roland-ramthun dot de Assigned:
Status: Closed Package: Date/time related
PHP Version: 5.5.3 OS: Linux
Private report: No CVE-ID: None
 [2013-08-25 14:03 UTC] mail at roland-ramthun dot de
Description:
------------
Comparison for DateTimeImmutable doesn't work. The same example with DateTime objects works.

Test script:
---------------
$a = new DateTimeImmutable('today');
$b = new DateTimeImmutable('tomorrow');

if ($a < $b) {
   print("yay");
}


Expected result:
----------------
yay

Actual result:
--------------
no output

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-27 23:44 UTC] cmbecker69 at gmx dot de
It seems that the comparison operators are not overloaded for
DateTimeImmutable objects.  Apparently they show the same behavior
as for arbitrary user defined classes.

If my assumption is correct, instead of adding a special treatment 
for the comparison operators wrt. DateTimeImmutable objects, it
might be considered to add a magic method __compare(). However,
I'm not sure, if this fits well with type juggling.
 [2013-09-12 13:15 UTC] nikic@php.net
Automatic comment on behalf of bsitnikovski@sugarcrm.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d7f5f1ef35c32d6943cd76a3c51752e8d64c5e5e
Log: Fix bug #65548: Comparison for DateTimeImmutable doesn't work
 [2013-09-12 13:15 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2013-11-17 09:30 UTC] laruence@php.net
Automatic comment on behalf of bsitnikovski@sugarcrm.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d7f5f1ef35c32d6943cd76a3c51752e8d64c5e5e
Log: Fix bug #65548: Comparison for DateTimeImmutable doesn't work
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC