Req #78401 [Fbk->Csd]: DateTime::modify signature change
| From: | kylekatarnls at gmail dot com | Date: | Mon, 12 Aug 2019 06:21:32 +0000 |
| Subject: | Req #78401 [Fbk->Csd]: DateTime::modify signature change | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222186@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78401&edit=1
ID: 78401
User updated by: kylekatarnls at gmail dot com
Reported by: kylekatarnls at gmail dot com
Summary: DateTime::modify signature change
-Status: Feedback
+Status: Closed
Type: Feature/Change Request
Package: Compile Failure
Operating System: Linux
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
Hi, sorry, my mistake, the method was not implemented. In fact I relied on the fact that both
DateTime and DateTimeImmutable have the modify() method, but as it's not declared in
DateTimeInterface (I don't know why, it would have seem logical), I had to declare it in my own
interface.
Now due to this change in PHP 8, I have to add
```
public function modify($modify)
{
return parent::modify((string) $modify);
}
```
So question for curiosity. Why DateTimeInterface does not declare all common methods of DateTime and
DateTimeImmutable.
Previous Comments:
------------------------------------------------------------------------
[2019-08-11 20:42:46] nikic@php.net
I can't reproduce this.
------------------------------------------------------------------------
[2019-08-11 20:06:30] kylekatarnls at gmail dot com
Description:
------------
My last Travis-CI test failed (while same code worked until there) for PHP 8.0.0-dev with the
following message:
Declaration of DateTime::modify(string $modify) must be compatible with I::modify($modify)
Test script:
---------------
interface I extends DateTimeInterface
{
modify($modify);
}
class A extends DateTime implements I
{
modify($modify) {}
}
Expected result:
----------------
I would expect my interface to be compatible with DateTime since it's covariant. I accept more
types but string is included so it should pass as there is no reason to forbid this extension.
Then I would be compatible with both PHP 7 and 8 but if I change the signature to a the string
typing, it will fail on PHP 7.
Actual result:
--------------
Declaration of DateTime::modify(string $modify) must be compatible with I::modify($modify)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78401&edit=1