Bug #65768 [Asn->Csd]: DateTimeImmutable::diff does not work

From: Date: Fri, 29 Nov 2013 22:33:35 +0000
Subject: Bug #65768 [Asn->Csd]: DateTimeImmutable::diff does not work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183019@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65768&edit=1 ID: 65768 Updated by: nikic@php.net Reported by: glenjamin at gmail dot com Summary: DateTimeImmutable::diff does not work -Status: Assigned +Status: Closed Type: Bug Package: Date/time related Operating System: OS X / Linux PHP Version: 5.5.4 Assigned To: derick Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2013-10-29 15:47:02] inefedor at gmail dot com Hi, I've added a PR on github. ------------------------------------------------------------------------ [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

« previous php.bugs (#183019) next »