Req #68061 [NEW]: DateTimeInterface::createFromInterface
| From: | evert at rooftopsolutions dot nl | Date: | Sat, 20 Sep 2014 01:15:55 +0000 |
| Subject: | Req #68061 [NEW]: DateTimeInterface::createFromInterface | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187617@lists.php.net to get a copy of this message | ||
From: evert at rooftopsolutions dot nl
Operating system: Any
PHP version: 5.6.0
Package: Date/time related
Bug Type: Feature/Change Request
Bug description:DateTimeInterface::createFromInterface
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 bug report at https://bugs.php.net/bug.php?id=68061&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68061&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68061&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68061&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68061&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68061&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68061&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68061&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68061&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68061&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68061&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68061&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68061&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68061&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68061&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68061&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68061&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68061&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68061&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68061&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68061&r=mysqlcfg