Bug #68187 [Opn->Dup]: Strange behavior DateInterval in PHP
| From: | cmb@php.net | Date: | Sun, 24 May 2015 15:44:47 +0000 |
| Subject: | Bug #68187 [Opn->Dup]: Strange behavior DateInterval in PHP | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-192860@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68187&edit=1
ID: 68187
Updated by: cmb@php.net
Reported by: e45456 at yandex dot ru
Summary: Strange behavior DateInterval in PHP
-Status: Open
+Status: Duplicate
Type: Bug
Package: Date/time related
Operating System: Ubuntu 14
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2014-10-13 05:11:35] 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.
------------------------------------------------------------------------
[2014-10-08 13:54:39] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68187&edit=1