Req #71520 [Opn]: Adding the DateTime constants to the DateTimeInterface interface
| From: | nyamsprod at gmail dot com | Date: | Sun, 07 Feb 2016 10:20:55 +0000 |
| Subject: | Req #71520 [Opn]: Adding the DateTime constants to the DateTimeInterface interface | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199087@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
User updated by: nyamsprod at gmail dot com
Reported by: nyamsprod at gmail dot com
Summary: Adding the DateTime constants to the
DateTimeInterface interface
Status: Open
Type: Feature/Change Request
Package: Date/time related
Operating System: Irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Another argument in favor of this move is to forbidden constant value override in DateTimeInterface
object subclasses
https://3v4l.org/iZEks
Previous Comments:
------------------------------------------------------------------------
[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