Re: DateTime improvement

From: Date: Mon, 10 Dec 2012 19:39:40 +0000
Subject: Re: DateTime improvement
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 10/12/12 16:18, Nikita Nefedov wrote:
> So there had been at least two or three messages (subjects) about
> DateTime object and everytime there was this problem - people tend to
> take DateTime object as mutable object and it really is.
> As long as we know, it's not so good - date is immutable by nature. I
> don't want to write here why it's so, I will just throw this link:
> http://www.ibm.com/developerworks/java/library/j-jtp02183/index.html
>
> I don't want to change any existing functionality, because some people
> already use it, but I just wanted to point out that current DateTime
> class is forcing people to think about it as mutable.
> My main concerns are DateTime#add() and DateTime#sub(). The problem is
> - they both change current object and return it.
> I think we could add methods to DateTime like add() and sub(), let's
> say plus() and minus(), but they would behave differently in the way
> that they would return new DateTime objects and won't change current
> object.
That will make it even more inconsistent.
You have add() and plus() but one changes the object and the other doesn't.

If we were going to rewrite php or the DateTime class, it could be a
good idea to make those methods  (or its equivalents) not modify the object.
But I don't think it'd be a win to do such thing now.



Thread (34 messages)

« previous php.internals (#64233) next »