From: glenjamin at gmail dot com
Operating system: OS X / Linux
PHP version: 5.5.4
Package: Date/time related
Bug Type: Bug
Bug description:DateTimeImmutable::diff does not work
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 bug report at https://bugs.php.net/bug.php?id=65768&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65768&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=65768&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65768&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65768&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65768&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65768&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65768&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65768&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65768&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65768&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65768&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65768&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65768&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65768&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65768&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65768&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65768&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65768&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65768&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65768&r=mysqlcfg