Re: [PR] DateTime::createFromImmutable() method

From: Date: Thu, 05 Mar 2015 13:45:46 +0000
Subject: Re: [PR] DateTime::createFromImmutable() method
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-84342@lists.php.net to get a copy of this message
Hi Trevor, I had no look to the code as I am no C or internals guru. I just wanted to add that I would prefer a generic DateTimeInterface::createFromInstance(DateTimeInterface $copyFrom) method, so you do not need to distinguish between DateTime and DateTimeImmutable when creating a new instance. That should have be done for the DateTimeImmutable, too. Otherwise you have to do the following: function doSomethingWithNewDate(\DateTimeInterface $date) { if ($date instanceof \DateTimeImmutable) { $newDate = \DateTime::createFromImmutable($date); } else { $newDate = clone $date; } } But if you want to create a new instance from a date, it should not matter if the source date is mutable or immutable. Thanks Dennis Am 05.03.2015 um 08:50 schrieb Trevor Suarez: > Good morning internals! > > I would like to propose a small addition be made to the DateTime class. > > https://github.com/php/php-src/pull/1145 > > This is my first contribution to PHP's core, beyond documentation edits. > I'm not sure on the formalities that need to be taken for something like > this to be considered as an addition, or if an email like this is even > appropriate, so I'd absolutely welcome any guidance here. > > I just saw a possible opportunity for an addition and thought it would be > fun to try and contribute to PHP. :) > > I'm not a C programmer by any means, so please forgive me if I've made any > "noob" mistakes here, haha. > > Thank you all for your time and consideration! > > > - Trevor >

« previous php.internals (#84342) next »