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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 - 5 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 19:01:28 2024 UTC