Req #71520 [Opn->Csd]: Adding the DateTime constants to the DateTimeInterface interface
| From: | nikic@php.net | Date: | Fri, 02 Jun 2017 22:57:07 +0000 |
| Subject: | Req #71520 [Opn->Csd]: Adding the DateTime constants to the DateTimeInterface interface | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209373@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71520&edit=1
ID: 71520
Updated by: nikic@php.net
Reported by: nyamsprod at gmail dot com
Summary: Adding the DateTime constants to the
DateTimeInterface interface
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Date/time related
Operating System: Irrelevant
PHP Version: Irrelevant
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Implemented by https://github.com/php/php-src/commit/637714cdaa80d1d3450df5186710b25b54463fa6.
Previous Comments:
------------------------------------------------------------------------
[2017-04-17 17:36:57] bugs dot php dot net at majkl578 dot cz
Hello, I've submitted a PR for this change, see here: https://github.com/php/php-src/pull/2483.
------------------------------------------------------------------------
[2016-02-07 10:20:52] nyamsprod at gmail dot com
Another argument in favor of this move is to forbidden constant value override in DateTimeInterface
object subclasses
https://3v4l.org/iZEks
------------------------------------------------------------------------
[2016-02-04 10:14:22] nyamsprod at gmail dot com
I'm suggesting to have them on the DateTimeInterface because:
- they are used by the DateTimeInterface::format method
- they are defined in RFCs that won't change during the lifetime of any implementing class
- DateTimeImmutable is supposed to be the immutable replica of DateTime so that one could completely
remove any reference to DateTime in his/her codebase when migrating from DateTime to
DateTimeImmutable.
------------------------------------------------------------------------
[2016-02-04 09:33:40] requinix@php.net
They aren't missing. The constants are on the DateTime class. Why should they be copied onto
DateTimeImmutable? What's wrong with keeping them on DateTime?
------------------------------------------------------------------------
[2016-02-04 09:25:51] nyamsprod at gmail dot com
Description:
------------
Currently it's not possible to access DateTime constants directly from DateTimeImmutable.
Test script:
---------------
$datetime = new DateTimeImmutable('2000-01-01 00:00:00', new
DateTimeZone('Africa/Kinshasa'));
var_dump($datetime->format(DateTimeImmutable::ATOM));
var_dump($datetime->format(DateTimeImmutable::COOKIE));
var_dump($datetime->format(DateTimeImmutable::ISO8601));
var_dump($datetime->format(DateTimeImmutable::RFC822));
var_dump($datetime->format(DateTimeImmutable::RFC850));
var_dump($datetime->format(DateTimeImmutable::RFC1036));
var_dump($datetime->format(DateTimeImmutable::RFC2822));
var_dump($datetime->format(DateTimeImmutable::RFC3339));
var_dump($datetime->format(DateTimeImmutable::RSS));
var_dump($datetime->format(DateTimeImmutable::W3C));
Expected result:
----------------
string(25) "2000-01-01T00:00:00+01:00"
string(34) "Saturday, 01-Jan-2000 00:00:00 WAT"
string(24) "2000-01-01T00:00:00+0100"
string(29) "Sat, 01 Jan 00 00:00:00 +0100"
string(32) "Saturday, 01-Jan-00 00:00:00 WAT"
string(29) "Sat, 01 Jan 00 00:00:00 +0100"
string(31) "Sat, 01 Jan 2000 00:00:00 +0100"
string(25) "2000-01-01T00:00:00+01:00"
string(31) "Sat, 01 Jan 2000 00:00:00 +0100"
string(25) "2000-01-01T00:00:00+01:00"
Actual result:
--------------
The following constant are missing on the DateTimeInterface interface
DateTimeInterface::ATOM,
DateTimeInterface::COOKIE,
DateTimeInterface::ISO8601,
DateTimeInterface::RFC822,
DateTimeInterface::RFC850,
DateTimeInterface::RFC1036,
DateTimeInterface::RFC2822,
DateTimeInterface::RFC3339,
DateTimeInterface::RSS,
DateTimeInterface::W3C
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71520&edit=1