php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78181 DateInterval can no longer be comparable according to its public properties
Submitted: 2019-06-19 11:00 UTC Modified: 2019-06-19 11:41 UTC
From: nyamsprod at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.4.0alpha1 OS: No relevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nyamsprod at gmail dot com
New email:
PHP Version: OS:

 

 [2019-06-19 11:00 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-19 11:03 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-06-19 11:03 UTC] 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:37 UTC] 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:41 UTC] nikic@php.net
This is already part of UPGRADING, see https://github.com/php/php-src/blob/PHP-7.4/UPGRADING#L50-L52.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC