|  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: -
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:
Status: Open Package: Date/time related
PHP Version: 5.6.0 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: evert at rooftopsolutions dot nl
New email:
PHP Version: OS:


 [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

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jan 26 06:01:23 2021 UTC