php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68187 Strange behavior DateInterval in PHP
Submitted: 2014-10-08 13:54 UTC Modified: 2015-05-24 15:44 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: e45456 at yandex dot ru Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: Irrelevant OS: Ubuntu 14
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: e45456 at yandex dot ru
New email:
PHP Version: OS:

 

 [2014-10-08 13:54 UTC] e45456 at yandex dot ru
Description:
------------
Strange behavior DateInterval in PHP.
I think it is a php bug.

Test script:
---------------
$i1 = DateInterval::createFromDateString('10 minutes');
$i2 = DateInterval::createFromDateString('30 minutes');
var_dump($i1 > $i2);
var_dump($i1 > $i2);
var_dump($i1);
var_dump($i1 > $i2);
var_dump($i1 > $i2);

Expected result:
----------------
bool(false)
bool(false)
object(DateInterval)#3 (8) {
  ...
}
bool(false)
bool(false)

Actual result:
--------------
bool(false)
bool(false)
object(DateInterval)#3 (8) {
  ...
}
bool(true)
bool(true)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-13 05:11 UTC] camporter1 at gmail dot com
I spent a bit of time trying to debug this, and noticed that the properties hashtable for the DateInterval object that is being dumped ends up getting elements added when using the get properties handler, whereas the other DateInterval's properties hashtable remains empty, since it isn't dumped.

The first comparison notices that both have the same element count, which causes the first result to be false. The second comparison sees that one properties hashtable has 15 elements vs 0 elements, due to having been dumped.
 [2015-05-24 15:44 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-05-24 15:44 UTC] cmb@php.net
As it is now, the comparison of DateInterval objects is
meaningless anyway. Even if the properties were initialized
immediately after creation, and if their order was guaranteed, the
standard comparison would not necessarily yield the expected
result, see <http://3v4l.org/KFqf5>.

The issue that properties of DateInterval objects are not
immediately available after construction is already reported as
bug #69587.

There is also a feature request for meaningful DateInterval
comparison (bug #49914).

Therefore I'm marking this report as duplicate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC