Re: DateTime::modify('now') is ignored, why?
| From: | Derick Rethans | Date: | Mon, 26 Nov 2012 12:50:00 +0000 |
| Subject: | Re: DateTime::modify('now') is ignored, why? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-64051@lists.php.net to get a copy of this message | ||
On Mon, 26 Nov 2012, Nikita Nefedov wrote:
> On Mon, 26 Nov 2012 15:06:09 +0400, Ivan Enderlin @ Hoa
> <ivan.enderlin@hoa-project.net> wrote:
>
> > I would to modify a \DateTime object to the current time, thus I
> > wrote this:
> >
> > $d = new \DateTime('+1 hour');
> > $d->modify('now');
> >
> > It did not work. Why? Because the documentation
> > (http://php.net/datetime.formats.relative) says: “Now - this is
> > simply ignored”. Really? But the behavior is pretty straightforward
> > isn't? “modify to now” means “set to the current date and time and
> > let the timezone unchanged”.
>
> Shouldn't DateTime be immutable? What's the point of DateTime object
> being mutable? I would include my point about why DateTime should be
> immutable but I even can't come with any points except OO-logic and
> all I can say is I just feel like mutable DateTime is wrong. What you
> think about it?
Yes, it should have been immutable. Biggest mistake that I made in this
API. We can't change it anymore though.
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine