# DateTimeInterface interface stub has no modify method

- Thread: https://externals.io/message/112329
- Original archive: https://news-web.php.net/php.internals/112329
- Started by vorismi3@fel.cvut.cz on 2020-12-01T15:34:54+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #112329 — vorismi3@fel.cvut.cz — 2020-12-01T15:34:54+00:00

URL: https://externals.io/message/112329#112329

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

---

## #112330 — Kamil Tekiela — 2020-12-01T15:39:59+00:00

URL: https://externals.io/message/112329#112330 · In reply to: #112329

Relevant: https://chat.stackoverflow.com/transcript/11?m=50929139

I also think it would be nice to have modify method in the interface
as at the moment the interface seems pretty useless. I was told this
would be BC and we are not going to change it now.

On Tue, 1 Dec 2020 at 15:35, 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

---

## #112331 — Nikita Popov — 2020-12-01T15:46:57+00:00

URL: https://externals.io/message/112329#112331 · In reply to: #112329

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
