Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62636 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71967 invoked from network); 1 Sep 2012 20:54:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2012 20:54:57 -0000 Authentication-Results: pb1.pair.com header.from=derick@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=derick@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 82.113.146.227 as permitted sender) X-PHP-List-Original-Sender: derick@php.net X-Host-Fingerprint: 82.113.146.227 xdebug.org Linux 2.6 Received: from [82.113.146.227] ([82.113.146.227:44201] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/F8-17065-F1672405 for ; Sat, 01 Sep 2012 16:54:57 -0400 Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 0ECEEDE13E; Sat, 1 Sep 2012 21:54:52 +0100 (BST) Date: Sat, 1 Sep 2012 21:54:51 +0100 (BST) X-X-Sender: derick@whisky.home.derickrethans.nl To: Will Fitch cc: PHP Developers Mailing List In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] RFC for Adding __toString to DateTime From: derick@php.net (Derick Rethans) On Sat, 1 Sep 2012, Will Fitch 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 default should most definitely not be ISO-8601 - as it's a lossy format. > The link to the RFC and patch are here: > https://wiki.php.net/rfc/datetime_tostring. > Methods Added > > void DateTime::setDefaultPattern(string $pattern) > string DateTime::getDefaultPattern(void) This should be descriptive. You are *only* dealing with __toString here. Hence the method names should reflect that: void DateTime::setToStringFormat(string $pattern) string DateTime::getToStringFormat(void) However, I still don't believe this belongs in the class at all. It is rather trivial to do this in userland: class MyDateTime extends DateTime { static $format = "... some format..."; function __toString() { return $this->format(DateTime::$format); } } There, 4 lines. And no quaralling about formats or naming. > $date = new DateTime('2012-09-01 02:43:00'); > print_r($date); Should not output just: > DateTime Object > ( > [date] => 2012-09-01 02:43:00 > [timezone_type] => 3 > [timezone] => America/Chicago > ) But instead should always have the tostring pattern in there. Also, have you checked whether it shows up when you run serialize on it? cheers, Derick