Bug #78181 [Nab]: DateInterval can no longer be comparable according to its public properties
| From: | nikic@php.net | Date: | Wed, 19 Jun 2019 11:41:03 +0000 |
| Subject: | Bug #78181 [Nab]: DateInterval can no longer be comparable according to its public properties | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221388@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78181&edit=1
ID: 78181
Updated by: nikic@php.net
Reported by: nyamsprod at gmail dot com
Summary: DateInterval can no longer be comparable according
to its public properties
Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: No relevant
PHP Version: 7.4.0alpha1
Block user comment: N
Private report: N
New Comment:
This is already part of UPGRADING, see https://github.com/php/php-src/blob/PHP-7.4/UPGRADING#L50-L52.
Previous Comments:
------------------------------------------------------------------------
[2019-06-19 11:37:57] nyamsprod at gmail dot com
So this is a bug fix from all previous PHP versions maybe it should be added in the CHANGES files
because the change in behaviour caught me off guard and I could not find any information in the
documentation regarding upgrades or changes or fix.
------------------------------------------------------------------------
[2019-06-19 11:03:59] nikic@php.net
DateInterval objects never compared according to their public properties -- they always compared
equal.
We may introduce comparable intervals (https://github.com/php/php-src/pull/4063), but they currently
do not exist and have never existed.
------------------------------------------------------------------------
[2019-06-19 11:00:26] nyamsprod at gmail dot com
Description:
------------
The DateInterval object exposes public properties. We should be able to compare two instances based
on their public properties like it is possible for any other object. It is the case currently in
PHP7.3-
Test script:
---------------
$interval1 = new DateInterval('PT3H');
$interval2 = new DateInterval('PT3H');
var_dump($interval1 == $interval2);
var_dump($interval1 === $interval2);
$obj1 = new stdClass();
$obj1->foo = 'bar';
$obj2 = new stdClass();
$obj2->foo = 'bar';
var_dump($obj1 == $obj2);
var_dump($obj1 === $obj2);
Expected result:
----------------
bool(true)
bool(false)
bool(true)
bool(false)
Actual result:
--------------
Warning: Cannot compare DateInterval objects in /in/G7jM0 on line 6
bool(false)
bool(false)
bool(true)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78181&edit=1