Bug #65768 [Com]: DateTimeImmutable::diff does not work
Edit report at https://bugs.php.net/bug.php?id=65768&edit=1
ID: 65768
Comment by: inefedor at gmail dot com
Reported by: glenjamin at gmail dot com
Summary: DateTimeImmutable::diff does not work
Status: Open
Type: Bug
Package: Date/time related
Operating System: OS X / Linux
PHP Version: 5.5.4
Block user comment: N
Private report: N
New Comment:
Hi, I've added a PR on github.
Previous Comments:
------------------------------------------------------------------------
[2013-09-26 15:03:44] glenjamin at gmail dot com
Description:
------------
Errors are generated when attempting to:
Diff a datetimeimmutable and a datetime
Diff a datetime and a datetimeimmutable
Diff a datetimeimmutable and another datetimeimmutable
The documentation implies that this should work correctly, and that diff() accepts DateTimeInterface
Test script:
---------------
$di1 = new DateTimeImmutable('now');
$di2 = new DateTimeImmutable('+1 hour');
$d = new DateTime('-1 hour');
$di1->diff($d); // DateInterval +1H
$di1->diff($di2); // DateInterval -1H
$d->diff($di1); // DateInterval +1H
Expected result:
----------------
DateInterval objects in all three cases
Actual result:
--------------
Produced via php -a
$di1->diff($d);
// PHP Fatal error: DateTime::diff() must be derived from DateTimeImmutable::diff in Unknown on
line 0
$di1->diff($di2); // DateInterval -1H
// PHP Fatal error: DateTime::diff() must be derived from DateTimeImmutable::diff in Unknown on
line 0
$d->diff($di1); // DateInterval +1H
// PHP Warning: DateTime::diff() expects parameter 1 to be DateTime, object given in php shell code
on line 1
// bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65768&edit=1
Thread (4 messages)