|  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
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
 [2014-10-08 13:54 UTC] e45456 at yandex dot ru
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 > $i2);
var_dump($i1 > $i2);

Expected result:
object(DateInterval)#3 (8) {

Actual result:
object(DateInterval)#3 (8) {


Add a Patch

Pull Requests

Add a Pull Request


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]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-05-24 15:44 UTC]
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 <>.

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-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 20:03:35 2022 UTC