Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66002 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72629 invoked from network); 19 Feb 2013 23:17:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2013 23:17:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:48699] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/22-61103-22804215 for ; Tue, 19 Feb 2013 18:17:55 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 97B41700043A; Tue, 19 Feb 2013 23:17:51 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id ZOKCz4rnCHmr; Tue, 19 Feb 2013 23:17:51 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 1DBD07000428; Tue, 19 Feb 2013 23:17:50 +0000 (WET) Received: from damnation.nl.lo.geleia.net (unknown [IPv6:2001:470:94a2:4:21d:baff:feee:cc0b]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id B3882200CB57; Tue, 19 Feb 2013 23:17:49 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Sanford Whiteman" , "Derick Rethans" Cc: "Nikita Popov" References: <1867201214.20130215192512@cypressintegrated.com> Date: Wed, 20 Feb 2013 00:17:45 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.12 (Linux) Subject: Re: [PHP-DEV] Questions regarding DateTimeImmutable From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Tue, 19 Feb 2013 13:01:18 +0100, Derick Rethans wrote: > On Fri, 15 Feb 2013, Sanford Whiteman wrote: > >> I think it was done to ease adoption even though it was known to >> violate LSP. To quote Stas, "As for established practice, everybody >> expects DateTime, so IMHO we should leave DateTime as base class even >> though it's not strictly OO-pure." This is not a matter of some abstract OO-pureness. The problem with the argument that "everybody 'typehints' DateTime; we should inherit from it so that the code will run when the pass it a DateTimeImmutable" is that it assumes that everybody who typehints DateTime uses DateTime in a manner compatible with DateTimeImmutable. I don't believe that no one relies on DateTime method's side effects -- I certainly do. >> This way does let users sub in DateTimeImmutable more easily and patch >> over a ton of unintended -- maybe not even fully noted or understood >> -- defects in their apps? I dunno. The argument is that people are using DateTime as if it were immutable and you can now fix this wrong code by passing a DateTimeImmutable instead? I find it highly unlikely. > Yes, that's exactly the idea. IMO, the classes should not be part of the same hierarchy. If it doesn't matter whether a DateTime or a DateTimeImmutable is passed, then don't typehint. An advantage of PHP is that you can use duck typing. If you do typehint, but then the subclasses break the post-conditions... what's the point? Even if most people DO use DateTime in a compatible way, this is a very myopic way to advance the language or handle a transition. If the DateTimeImmutable interface is superior, people will move to it. If it's important for functions to accept both (I don't think it is), a common superclass with weaker guarantees can be extracted. -- Gustavo Lopes