Bug #77854 [Opn->Fbk]: DateTime object comparison wrong
| From: | requinix@php.net | Date: | Fri, 05 Apr 2019 16:37:51 +0000 |
| Subject: | Bug #77854 [Opn->Fbk]: DateTime object comparison wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220333@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77854&edit=1
ID: 77854
Updated by: requinix@php.net
Reported by: Stephan dot Hartmann at flyeralarm dot com
Summary: DateTime object comparison wrong
-Status: Open
+Status: Feedback
Type: Bug
Package: Date/time related
Operating System: Ubuntu
PHP Version: 7.1.28
Block user comment: N
Private report: N
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
Using the current time is not repeatable. Please pick a specific time.
PHP 7.1 is no longer in active support, but I can't reproduce this behavior with it anyways.
https://3v4l.org/3vaor
Previous Comments:
------------------------------------------------------------------------
[2019-04-05 11:53:24] Stephan dot Hartmann at flyeralarm dot com
Description:
------------
Only in php7.1 relevant, php5.6 and php7.2 not
Comparing two DateTime objects fails even if they are identical.
Problem is probably float arithmetic because $date->diff($date1) != 0.
Test script:
---------------
<?php
$date = new DateTime();
$date1 = unserialize(serialize($date));
$date2 = new DateTime($date->format('Y-m-d H:i:s.u'));
print_r("start php version ".phpversion());
print_r("\n");
print_r("\n");
print_r("date==date1:");
print_r($date==$date1);
print_r("\n");
print_r("date==date2:");
print_r($date==$date2);
print_r("\n");
print_r("date1==date2:");
print_r($date1==$date2);
print_r("\n");
print_r("finish");
Expected result:
----------------
start php version 7.2.15-0ubuntu0.18.04.2
date==date1:1
date==date2:1
date1==date2:1
finish
Process finished with exit code 0
Actual result:
--------------
start php version 7.2.15-0ubuntu0.18.04.2
date==date1:
date==date2:
date1==date2:1
finish
Process finished with exit code 0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77854&edit=1