Bug #77854 [NEW]: DateTime object comparison wrong

From: Date: Fri, 05 Apr 2019 11:53:24 +0000
Subject: Bug #77854 [NEW]: DateTime object comparison wrong
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220330@lists.php.net to get a copy of this message
From:             Stephan dot Hartmann at flyeralarm dot com
Operating system: Ubuntu
PHP version:      7.1.28
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime object comparison wrong

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 bug report at https://bugs.php.net/bug.php?id=77854&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=77854&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=77854&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=77854&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=77854&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=77854&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=77854&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=77854&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=77854&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=77854&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=77854&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=77854&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=77854&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=77854&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77854&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=77854&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=77854&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=77854&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77854&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=77854&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=77854&r=mysqlcfg



Thread (10 messages)

« previous php.bugs (#220330) next »