php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65768 DateTimeImmutable::diff does not work
Submitted: 2013-09-26 15:03 UTC Modified: 2013-11-03 11:53 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: glenjamin at gmail dot com Assigned: derick
Status: Closed Package: Date/time related
PHP Version: 5.5.4 OS: OS X / Linux
Private report: No CVE-ID:
 [2013-09-26 15:03 UTC] 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)

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-29 15:47 UTC] inefedor at gmail dot com
Hi, I've added a PR on github.
 [2013-11-03 11:53 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2013-11-29 22:33 UTC] nikic@php.net
Automatic comment on behalf of inefedor@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5f09944662e09ea0b3f93cfab8702f188955e68c
Log: Fixed bug #65768: DateTimeImmutable::diff does not work
 [2013-11-29 22:33 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2013-12-01 11:32 UTC] ab@php.net
Automatic comment on behalf of inefedor@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5f09944662e09ea0b3f93cfab8702f188955e68c
Log: Fixed bug #65768: DateTimeImmutable::diff does not work
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 14:02:33 2014 UTC