# DateTimeImmutable

- Thread: https://externals.io/message/66822
- Original archive: https://news-web.php.net/php.internals/66822
- Started by Michael Wallner on 2013-03-26T19:29:07+00:00
- Messages: 18
- 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

---

## #66822 — Michael Wallner — 2013-03-26T19:29:07+00:00

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

Hi all!

I am concerned by the introduction of DateTimeImmutable extending
DateTime, and despite not being the talking guy, I'll try to outline
the reasons why I and obviously a lot of other people think so.

I can understand the frustration with a DateTime that should not have
been modifiable in the first place and the wish to improve upon things
and to lead users to the proper way. But, this is not the right way.

If interoperability was in mind, it will not be given, because every
single API which has been written in the last seven years and has
DateTime in it's signature is potentially broken.  The code may and
should be able to expect a modifiable instance of DateTime, which is
no longer guaranteed.

The argument, that it was implemented this way, so that method
signatures do not have to be changed, is weak, because every method
has to be reviewed, and a method signature change would actually be
the right thing to accept a DateTimeImmutable, because it does not act
like a DateTime.

It will lead to lots of boilerplate typechecking code with instanceof
because it actually is not the same type. DateTimeImmutable extending
DateTime will instantly create BC issues, which we will suffer from a
long time.

The toughtful developer, which already cloned the DateTimes in his
methods won't benefit either, because now he's cloning
DateTimeImmutables.

In my opinion, the only way to "solve" this issue is through
documentation, advocation, publication and providing DateTimeImmutable
as a sibling to DateTime.

DateTime is here, and we cannot go back in time, but we might
deprecate DateTime* and introduce a date namespace in PHP-next to
clean up this front, but this already goes beyond the issue with
DateTimeImmutable.


-- 
Regards,
Mike

---

## #66824 — Ferenc Kovacs — 2013-03-27T08:03:00+00:00

URL: https://externals.io/message/66822#66824 · In reply to: #66822

2013.03.26. 20:29, "Michael Wallner" <mike@php.net> ezt írta:
>
> Hi all!
>
> I am concerned by the introduction of DateTimeImmutable extending
> DateTime, and despite not being the talking guy, I'll try to outline
> the reasons why I and obviously a lot of other people think so.
>
> I can understand the frustration with a DateTime that should not have
> been modifiable in the first place and the wish to improve upon things
> and to lead users to the proper way. But, this is not the right way.
>
> If interoperability was in mind, it will not be given, because every
> single API which has been written in the last seven years and has
> DateTime in it's signature is potentially broken.  The code may and
> should be able to expect a modifiable instance of DateTime, which is
> no longer guaranteed.
>
> The argument, that it was implemented this way, so that method
> signatures do not have to be changed, is weak, because every method
> has to be reviewed, and a method signature change would actually be
> the right thing to accept a DateTimeImmutable, because it does not act
> like a DateTime.
>
> It will lead to lots of boilerplate typechecking code with instanceof
> because it actually is not the same type. DateTimeImmutable extending
> DateTime will instantly create BC issues, which we will suffer from a
> long time.
>
> The toughtful developer, which already cloned the DateTimes in his
> methods won't benefit either, because now he's cloning
> DateTimeImmutables.
>
> In my opinion, the only way to "solve" this issue is through
> documentation, advocation, publication and providing DateTimeImmutable
> as a sibling to DateTime.
>
> DateTime is here, and we cannot go back in time, but we might
> deprecate DateTime* and introduce a date namespace in PHP-next to
> clean up this front, but this already goes beyond the issue with
> DateTimeImmutable.
>
>
> --
> Regards,
> Mike
>
> --
> 
> 
>

would it make sense to introduce an interface wich both DateTime and
DateTimeImmutable implements?
that way you can typehint for both if you know that both classes are fine
for you.

---

## #66828 — Lars Strojny — 2013-03-27T12:18:16+00:00

URL: https://externals.io/message/66822#66828 · In reply to: #66824

Not really, as an interface guarantees behavior, which is not possible for DateTimeImmutable and DateTime.

Am 27.03.2013 um 09:03 schrieb Ferenc Kovacs <tyra3l@gmail.com>:

> 2013.03.26. 20:29, "Michael Wallner" <mike@php.net> ezt írta:
> > […]
> 
> would it make sense to introduce an interface wich both DateTime and
> DateTimeImmutable implements?
> that way you can typehint for both if you know that both classes are fine
> for you.

---

## #66829 — Jordi Boggiano — 2013-03-27T12:41:14+00:00

URL: https://externals.io/message/66822#66829 · In reply to: #66828

> Not really, as an interface guarantees behavior, which is not possible for DateTimeImmutable and DateTime.

The interface could be a subset of DateTime public methods, including
only the readonly ones.

I can't imagine how this could possibly be named in a sane way though :/

Cheers

-- 
Jordi Boggiano
@seldaek - http://nelm.io/jordi

---

## #66831 — Andreas Heigl — 2013-03-27T12:49:17+00:00

URL: https://externals.io/message/66822#66831 · In reply to: #66829

Am 27.03.13 13:41, schrieb Jordi Boggiano:
> 
> > […]
> 
> The interface could be a subset of DateTime public methods, including
> only the readonly ones.
> 
> I can't imagine how this could possibly be named in a sane way though :/

DateTimeInterface or DateTimeROInterface?

Cheers
> 
> Cheers
> 


-- 
                                                              ,,,
                                                             (o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl                                                       |
| mailto:andreas@heigl.org                  N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org                       http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca                                               |
+---------------------------------------------------------------------+

---

## #66832 — Pierre Joye — 2013-03-27T13:14:28+00:00

URL: https://externals.io/message/66822#66832 · In reply to: #66831

> Am 27.03.13 13:41, schrieb Jordi Boggiano:
> > […]
>
> DateTimeInterface or DateTimeROInterface?


I'd to re post Lars suggestion from another thread. Do a RFC. This is
going again in all possible directions and I fear that we will not get
a good solution at the end of the day.

Cheers,
--
Pierre

@pierrejoye

---

## #66834 — Steve Clay — 2013-03-27T14:57:32+00:00

URL: https://externals.io/message/66822#66834 · In reply to: #66822

> I am concerned by the introduction of DateTimeImmutable extending
> DateTime
...
> If interoperability was in mind, it will not be given, because every
> single API which has been written in the last seven years and has
> DateTime in it's signature is potentially broken.  The code may and
> should be able to expect a modifiable instance of DateTime, which is
> no longer guaranteed.
...
> In my opinion, the only way to "solve" this issue is through
> documentation, advocation, publication and providing DateTimeImmutable
> as a sibling to DateTime.

Much agreed. DateTimeImmutable is welcomed as a better design, but it is not a clean 
substitute for a DataTime object.


Steve Clay
-- 
http://www.mrclay.org/

---

## #66835 — Ferenc Kovacs — 2013-03-27T16:10:31+00:00

URL: https://externals.io/message/66822#66835 · In reply to: #66832

> 
> > […]
> for DateTimeImmutable and DateTime.
> > […]
>
>
> I'd to re post Lars suggestion from another thread. Do a RFC. This is
> going again in all possible directions and I fear that we will not get
> a good solution at the end of the day.
>
> Cheers,
> --
> Pierre
>
> @pierrejoye
>
> --
> 
> 
>
>
agree, but the current implementation shouldn't be shipped until we find an
acceptable solution.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #66837 — johannes@schlueters.de — 2013-03-27T17:06:46+00:00

URL: https://externals.io/message/66822#66837 · In reply to: #66835

> agree, but the current implementation shouldn't be shipped until we
> find an acceptable solution. 

+1

johannes

---

## #66842 — Derick Rethans — 2013-03-27T20:53:47+00:00

URL: https://externals.io/message/66822#66842 · In reply to: #66822

> providing DateTimeImmutable as a sibling to DateTime.

That's fine with me, but I am not having the time to work on a patch 
right now.

cheers,
Derick

---

## #66845 — Lars Strojny — 2013-03-28T09:04:44+00:00

URL: https://externals.io/message/66822#66845 · In reply to: #66842

Hi Derick,

Am 27.03.2013 um 21:53 schrieb Derick Rethans <derick@php.net>:

> 
> 
> > […]
> 
> That's fine with me, but I am not having the time to work on a patch 
> right now.

Happens. Let’s revert it till somebody finds some time to do it. Could you revert it?

cu,
Lars

---

## #66846 — Nikita Nefedov — 2013-03-28T09:26:00+00:00

URL: https://externals.io/message/66822#66846 · In reply to: #66845

> Hi Derick,
>
> Am 27.03.2013 um 21:53 schrieb Derick Rethans <derick@php.net>:
>
> > […]
>
> Happens. Let’s revert it till somebody finds some time to do it. Could  
> you revert it?
>
> cu,
> Lars
> --
> 
> 
>

Hi,

Sorry, maybe I missed something, but what the consensus did we achieve  
here?
Make an interface? Or maybe make an abstract class with constructor, late  
static binded fabric methods (which btw could solve problems with making  
custom datetime class in userland), and some of the methods like diff and  
so on? Or maybe something else?

PS I think I can make a patch on these weekends.

---

## #66847 — Lester Caine — 2013-03-28T09:57:33+00:00

URL: https://externals.io/message/66822#66847 · In reply to: #66846

Nikita Nefedov wrote:
> Sorry, maybe I missed something, but what the consensus did we achieve here?
> Make an interface? Or maybe make an abstract class with constructor, late static
> binded fabric methods (which btw could solve problems with making custom
> datetime class in userland), and some of the methods like diff and so on? Or
> maybe something else?

I think that the general consensus is that this needs to have a proper RFC 
generated and all the ramifications investigated properly? It's not the '5 
minute fix' that was originally thought. When DateTime was first added it caused 
a lot of problems simply because there were/are other library elements doing the 
same job and clashing. This is perhaps an area where the original design was the 
problem since many people seem to think that it was wrong, so 'correcting' it 
needs proper consideration?

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

---

## #66848 — Derick Rethans — 2013-03-28T11:05:44+00:00

URL: https://externals.io/message/66822#66848 · In reply to: #66845

> Am 27.03.2013 um 21:53 schrieb Derick Rethans <derick@php.net>:
> 
> > […]
> 
> Happens. Let’s revert it till somebody finds some time to do it. Could 
> you revert it?

No, let's not revert it.

cheers,
Derick

---

## #66849 — Santiago Lizardo — 2013-03-28T11:09:35+00:00

URL: https://externals.io/message/66822#66849 · In reply to: #66848

I'm on my easter holidays and I have some spare time to revert the changes
introduced by the DateTimeImmutable for you Derick. Please let me know if
you want me to do it.




> 
>
> > […]
>
> No, let's not revert it.
>
> cheers,
> Derick

---

## #66850 — Pierre Joye — 2013-03-28T11:17:58+00:00

URL: https://externals.io/message/66822#66850 · In reply to: #66848

> 
>
> > […]
>
> No, let's not revert it.

I'd rather revert until a consensus is reached. Having a sub optimal
solution, at best, only because one or more developers did not get the
time to sit down on it is not going to be a good way to get new
features in php.

Can't make it for 5.5? 5.6 is in around a year, we lived years without
this, we can wait one more year.

Cheers,
--
Pierre

@pierrejoye

---

## #66851 — Derick Rethans — 2013-03-28T12:18:01+00:00

URL: https://externals.io/message/66822#66851 · In reply to: #66849

> I'm on my easter holidays and I have some spare time to revert the changes
> introduced by the DateTimeImmutable for you Derick. Please let me know if
> you want me to do it.

No, don't revert it. It needs to be a sibling class to DateTime instead 
of inherited like it is now.

cheers,
Derick

---

## #66855 — Derick Rethans — 2013-03-29T09:35:01+00:00

URL: https://externals.io/message/66822#66855 · In reply to: #66829

> 
>
> > […]
> 
> The interface could be a subset of DateTime public methods, including
> only the readonly ones.
> 
> I can't imagine how this could possibly be named in a sane way though :/

Name aside, an interface is sort of very useful otherwise we're ending 
up with code like this all over the time:

        first_arg_ce = zend_get_class_entry(start);
        if ((first_arg_ce != date_ce_date) && (first_arg_ce != date_ce_immutable)) {

And that's a real pain, so an interface for just the gettings (and other 
methods not modifying/changing anything is probably a good idea. I'll 
see if I can work on this over the Easter weekend.

cheers,
Derick
