Some Thoughts on PHP's DateTime, Object Mutability and an Alternative Implementation

Posted in PHP on Thursday, the 22nd of September, 2011.

I'm beginning think that while the introduction of PHP's newish DateTime object is very welcome, its implementation is one of the big missed opportunities in the language. This is because the decision was taken to make it mutable. In essence, DateTime has been implemented as an Entity rather than a Value Object.


Posted by David Allen on Tuesday, the 29th of November, 2011.

HI there,
We are thinking of implementing a similar object but I thought I would first google and see what I came up with.
Your object looks good.
However, you wrote it is not production ready.
What did you mean by that?

Posted by Simon Harris on Tuesday, the 29th of November, 2011.

Thanks, David.

I should really update that point, as the code is ready for use now. I'd be happy for people to use it, make suggestions and even send pull requests.

Posted by Ciaran McNulty on Monday, the 9th of December, 2013.

For anyone who finds this on Google, PHP 5.5 now contains a DateTimeImmutable object that operates much like Simon describes here.

Enter your comment: