| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2019-04-05 11:53 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 12:00:01 2025 UTC | 
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;