Re: RFC for Adding __toString to DateTime
| From: | Sherif Ramadan | Date: | Sat, 01 Sep 2012 11:31:11 +0000 |
| Subject: | Re: RFC for Adding __toString to DateTime | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62631@lists.php.net to get a copy of this message | ||
On Sat, Sep 1, 2012 at 6:14 AM, Will Fitch <willfitch@php.net> wrote:
> I would like to officially introduce an RFC with a patch to implement
> __toString to DateTime. This is a commonly requested feature that goes
> unanswered mostly because of the inability to agree on a default pattern.
>
> In short, the patch uses the ISO-8601 format as the default pattern. The
> pattern may be changed via setDefaultPattern and date_default_pattern_set,
> as explained in the RFC.
>
> The link to the RFC and patch are here:
> https://wiki.php.net/rfc/datetime_tostring.
>
> While I know this isn't as interesting as many of the current proposals
> going on, I'm hoping you can give this RFC a look.
>
> - Will
I think you should consider making the get/setDefaultPattern() methods
into a public string called $format and just put it in the constructor
with an initial value of DateTime::ISO8601
It'd be a much simple implementation and doesn't require introducing
new functions. DateTime can either throw an exception if the format is
invalid or silently fall back to the DateTime::ISO8601
No need to complicate this.