Req #62911 [Asn->Wfx]: Add DateTime::__toString()

From: Date: Mon, 27 Aug 2012 15:17:38 +0000
Subject: Req #62911 [Asn->Wfx]: Add DateTime::__toString()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-172951@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62911&edit=1

 ID:                 62911
 Updated by:         derick@php.net
 Reported by:        bdurand-php at ssji dot net
 Summary:            Add DateTime::__toString()
-Status:             Assigned
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Date/time related
 PHP Version:        Irrelevant
 Assigned To:        willfitch
 Block user comment: N
 Private report:     N

 New Comment:

We have had this a few times now, and we should not do this. The main reason is that we will never
be able to come to a consensus on which format to show. It certainly shouldn't have anything
that destroys the encoded timezone identifiers.

It's perfectly possible to subclass DateTime yourself and add a __toString() that returns the
datetime in your preferred format though.


Previous Comments:
------------------------------------------------------------------------
[2012-08-27 15:15:15] willfitch@php.net

This is a good idea.  I will add this, but will also add an RFC as I'd like the 
input of other internals on the output format.

------------------------------------------------------------------------
[2012-08-23 18:15:37] bdurand-php at ssji dot net

Description:
------------
Hello,

I want to have a default behavior to convert an instance of the class DateTime into a string. I mean
implement the method __toString() in the DateTime class.

The default format should be ISO8601 IMHO, but we can add an attribut to define the default format
to use for __toString() and format() method.

Greetings.

Test script:
---------------
<?php
$datetime = new DateTime();
echo $datetime;

Expected result:
----------------
2012-08-23T20:11:21+0200

Actual result:
--------------
PHP Catchable fatal error:  Object of class DateTime could not be converted to string in php shell
code on line 1


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62911&edit=1


Thread (11 messages)

« previous php.bugs (#172951) next »