|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #68061 DateTimeInterface::createFromInterface
Submitted: 2014-09-20 01:15 UTC Modified: 2021-03-04 13:14 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: evert at rooftopsolutions dot nl Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 5.6.0 OS: Any
Private report: No CVE-ID: None
 [2014-09-20 01:15 UTC] evert at rooftopsolutions dot nl
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:


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 :


In the case of a DateTime we would get a Immutable copy of it, in the case of DateTimeImmutable, it can just return itself.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-04 13:14 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-03-04 13:14 UTC]
DateTime::createFromInterface() and DateTimeImmutable::createFromInterface()
are available as of PHP 8.0.0.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Jun 08 05:03:37 2023 UTC