Re: DateTimeInterface interface stub has no modify method
| From: | Nikita Popov | Date: | Tue, 01 Dec 2020 15:46:57 +0000 |
| Subject: | Re: DateTimeInterface interface stub has no modify method | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112331@lists.php.net to get a copy of this message | ||
On Tue, Dec 1, 2020 at 4:35 PM Michael Voříšek - ČVUT FEL <
vorismi3@fel.cvut.cz> wrote:
> Intentionally?
>
> It is an issue for static analysers...
>
> With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem,
>
> Michael Voříšek
> ČVUT FEL
Yes, this is intentional. The DateTimeInterface interface (has absolutely
nothing to do with stubs -- this is the same in PHP 7) only includes the
methods that are present in both DateTime and DateTimeImmuatable **with the
same behavior**.
DateTime::modify() and DateTimeImmutable::modify(), while having the same
signature, do completely different things. One performs an in-place
modification, while the other doesn't.
You should be doing one of two things:
1. Only accept DateTimeImmutable.
2. Accept DateTimeInterface and then use
DateTimeImmutable::createFromInterface() to convert it into a
DateTimeImmutable.
Working on a plain DateTimeInterface only makes sense if you are using the
read-only methods, which are the ones that are part of the
DateTimeInterface interface.
Regards,
Nikita