|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-08-11 20:06 UTC] 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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 UTC |
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.