Doc #71053 [NEW]: Type Hint about DateTime::diff does not match with informed
| From: | gabriel dot heming at hotmail dot com | Date: | Mon, 07 Dec 2015 20:08:17 +0000 |
| Subject: | Doc #71053 [NEW]: Type Hint about DateTime::diff does not match with informed | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-12908@lists.php.net to get a copy of this message | ||
From: gabriel dot heming at hotmail dot com
Operating system: Debian 8.2
PHP version: 7.0.0
Package: SPL related
Bug Type: Documentation Problem
Bug description:Type Hint about DateTime::diff does not match with informed
Description:
------------
The second parameter (or third one) of method DateTime::diff must be a
bool (as described in php documentation). AS can see below
http://php.net/manual/en/datetime.diff.php
Object oriented style:
public DateInterval DateTime::diff ( DateTimeInterface $datetime2 [,
bool $absolute = false ] );
public DateInterval DateTimeImmutable::diff ( DateTimeInterface
$datetime2 [, bool $absolute = false ] );
public DateInterval DateTimeInterface::diff ( DateTimeInterface
$datetime2 [, bool $absolute = false ] );
Test script:
---------------
<?php
declare(strict_types=1);
$date1 = clone $date2 = new \DateTime();
var_dump($date1->diff($date2 , true));
Expected result:
----------------
object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(0)
["d"]=>
int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0)
["weekday"]=> int(0)
["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0)
["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=>
int(0)
["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0)
["have_special_relative"]=> int(0) }
Actual result:
--------------
Fatal error: Uncaught TypeError: DateTime::diff() expects parameter 2 to
be integer, boolean given in /code/3uk3Qo:6 Stack trace: #0
/code/3uk3Qo(6): DateTime->diff(Object(DateTime), true) #1 {main} thrown
in /code/3uk3Qo on line 6
--
Edit bug report at https://bugs.php.net/bug.php?id=71053&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71053&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71053&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71053&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71053&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71053&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71053&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71053&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71053&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71053&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71053&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71053&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71053&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71053&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71053&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71053&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71053&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71053&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71053&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71053&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71053&r=mysqlcfg