Req #68061 [Opn->Csd]: DateTimeInterface::createFromInterface
| From: | cmb@php.net | Date: | Thu, 04 Mar 2021 13:14:31 +0000 |
| Subject: | Req #68061 [Opn->Csd]: DateTimeInterface::createFromInterface | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232549@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68061&edit=1
ID: 68061
Updated by: cmb@php.net
Reported by: evert at rooftopsolutions dot nl
Summary: DateTimeInterface::createFromInterface
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Date/time related
Operating System: Any
PHP Version: 5.6.0
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
DateTime::createFromInterface() and DateTimeImmutable::createFromInterface()
are available as of PHP 8.0.0.
Previous Comments:
------------------------------------------------------------------------
[2014-09-20 01:15:54] evert at rooftopsolutions dot nl
Description:
------------
I am currently in the process of migrating my codebase to PHP 5.5
I do a lot of stuff with dates, so a big thing for me is to move everything to DateTimeImmutable.
What this generally implies for me is:
1. I accept DateTimeInterface everywhere.
2. I emit DateTimeImmutable everywhere.
Often times I will want to work internally with DateTimeImmutable. So I really need a way to
'cast' whatever I have to DateTimeImmutable.
Unfortunately we only have:
DateTimeImmutable::createFromMutable
This means that I'll generally always have to check if I got a DateTime or DateTimeInterface,
and only call createFromMutable _if_ it's a DateTime object.
No huge deal, but it would be nicer if I can always call:
DateTimeMutable::createFromInterface(DateTimeInterface $dt).
But one step beyond that would be, and would be even more convenient, is if DateTimeInterface got a
method :
getImmutable()
In the case of a DateTime we would get a Immutable copy of it, in the case of DateTimeImmutable, it
can just return itself.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68061&edit=1