Bug #77854 [Com]: DateTime object comparison wrong

From: Date: Wed, 10 Apr 2019 12:35:15 +0000
Subject: Bug #77854 [Com]: DateTime object comparison wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220391@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
 Comment by:         Stephan dot Hartmann at flyeralarm dot com
 Reported by:        Stephan dot Hartmann at flyeralarm dot com
 Summary:            DateTime object comparison wrong
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Ubuntu
 PHP Version:        7.1.28
 Block user comment: N
 Private report:     N

 New Comment:

https://github.com/Talarion291/phpalpinebug

check this out for minimal example


Previous Comments:
------------------------------------------------------------------------
[2019-04-08 14:09:40] Stephan dot Hartmann at flyeralarm dot com

Using the php:7.1.27-cli-stretch image from dockerhub passes the testscript.
Using the php:7.1.28-cli-alpine image from dockerhub fails the testscript, hinting that the whole
php:7.1.*-cli-alpine images are affected.

------------------------------------------------------------------------
[2019-04-08 08:00:22] Stephan dot Hartmann at flyeralarm dot com

More precisely its the 4 week old PHP 7.1.27 (cli) (built: Mar 0 2019 03:44:52)
php 7.1-cli-alpine e6492c17926d 4 weeks ago 70MB

------------------------------------------------------------------------
[2019-04-08 07:42:43] Stephan dot Hartmann at flyeralarm dot com

After compiling 7.1.27 locally on my machine (Ubuntu 18.04.02) this minimal example passes, while on
the current "php:7.1-cli-alpine" docker image from docker hub this minimal example fails.
Please try to reproduce bug using said image.
Additionally using $date = new DateTime('2019-04-05 12:34:56.123456'); passes both times,
while using $date = new DateTime(); fails in docker image;

------------------------------------------------------------------------
[2019-04-05 16:37:51] requinix@php.net

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

------------------------------------------------------------------------
[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


Thread (10 messages)

« previous php.bugs (#220391) next »