php.net |  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
Votes:2
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: evert at rooftopsolutions dot nl
New email:
PHP Version: OS:

 

 [2014-09-20 01:15 UTC] 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.






Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-04 13:14 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-03-04 13:14 UTC] cmb@php.net
DateTime::createFromInterface() and DateTimeImmutable::createFromInterface()
are available as of PHP 8.0.0.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 21:01:27 2025 UTC