Doc #71053 [Opn]: Type Hint about DateTime::diff does not match with informed

From: Date: Mon, 07 Dec 2015 20:19:08 +0000
Subject: Doc #71053 [Opn]: Type Hint about DateTime::diff does not match with informed
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12909@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71053&edit=1 ID: 71053 User updated by: gabriel dot heming at hotmail dot com Reported by: gabriel dot heming at hotmail dot com Summary: Type Hint about DateTime::diff does not match with informed Status: Open Type: Documentation Problem -Package: SPL related +Package: *General Issues Operating System: Debian 8.2 PHP Version: 7.0.0 Block user comment: N Private report: N New Comment: The same strange behavior occurs when try to inherits DateTime: Declaration of MyDateTime::diff(DateTimeInterface $object, bool $absolute = false) must be compatible with DateTimeInterface::diff($object, $absolute = NULL) Previous Comments: ------------------------------------------------------------------------ [2015-12-07 20:08:15] gabriel dot heming at hotmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=71053&edit=1

« previous php.doc.bugs (#12909) next »