Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66035 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60752 invoked from network); 20 Feb 2013 09:16:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2013 09:16:16 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 74.125.82.44 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:44096] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/97-19387-C5494215 for ; Wed, 20 Feb 2013 04:16:13 -0500 Received: by mail-wg0-f44.google.com with SMTP id dr12so6275938wgb.35 for ; Wed, 20 Feb 2013 01:16:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:x-originating-ip:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=2edPLjQ8G/7uOHVrnI5gVClFPk0BAineZo8o2io5p3M=; b=K3ieB4s3NJLojpHkaH0ABtxfPBVySbuJddJPXZ0HE6+qbkwzgMpVovNhz3lX8csfgk P690GBghUP4iVyQA66waQ6u4j7vW/9G2tpdj9LBwzZwia9nJJmWAr1Dij66YOlYIyfQu wYfARRSU/OQyQeVGh3QGnMEeMaAp/VXy2RlJy38DX+chm7gy7Bln3Eb2+exNYDDW1NHG E5sTqpgJIPG3RHNC2tTU0Xtvit2HzPAkz+RzrRHz+TdtreWGVNC/aULSMOPSOMoazNh0 sR6SegDoMG2WcEU64NeSQ62ibJpRAm+GHidj7qwoOYqjEHhnyZIbt2hvDiicOXrJ793/ x2uw== MIME-Version: 1.0 X-Received: by 10.180.72.148 with SMTP id d20mr32453042wiv.31.1361351768211; Wed, 20 Feb 2013 01:16:08 -0800 (PST) Received: by 10.194.5.233 with HTTP; Wed, 20 Feb 2013 01:16:08 -0800 (PST) X-Originating-IP: [77.11.89.24] In-Reply-To: References: <1867201214.20130215192512@cypressintegrated.com> <51248C24.4070609@sugarcrm.com> Date: Wed, 20 Feb 2013 10:16:08 +0100 Message-ID: To: Gustavo Lopes Cc: Stas Malyshev , Derick Rethans , PHP Internals Content-Type: multipart/alternative; boundary=f46d043be21c8f002804d624684d X-Gm-Message-State: ALoCoQmf++v9CDB9ZgBt13o5fxa19fU4EkTFrqTdjxPk6d5C/VBmskqufPjel0WO/fnvehKEv0p5 Subject: Re: [PHP-DEV] Questions regarding DateTimeImmutable From: kontakt@beberlei.de (Benjamin Eberlei) --f46d043be21c8f002804d624684d Content-Type: text/plain; charset=ISO-8859-1 The problem with DateTimeImmutable extends DateTime is, that the client code not just magically works with immutable date times, it also works differently with regard to state, so this will be a source of subtle and annoying bugs. See the following example: https://gist.github.com/beberlei/4994193 The client code actually has to know if the instance is DateTime or DateTimeImmutable and behave differently. Or just use "clone" as before, and then there is no difference to pre 5.5 code anyways. On Wed, Feb 20, 2013 at 10:07 AM, Gustavo Lopes wrote: > Em 2013-02-20 9:41, Stas Malyshev escreveu: > > There's nothing that "everybody" is >> doing - there are tons of different usage patterns, some of them common, >> some incompatible. We need to look on what is more probable - that >> people use DateTime as hint for operations that do not modify the >> incoming object or that they do modify it and also would put >> DateTimeImmutable in this code. >> > > No, we do not need to look on what is more probable. It's only when we > select this very ill-advised option, that we need to start guessing if > people used all the guarantees of DateTime (namely its side-effects) or not. > > > So on one side we have existing code that would not accept >> DateTimeImmutable without extensive modification, >> > > To "accept a DateTimeImmutable" is not the same as "no recoverable fatal > error when a DateTimeImmutable is passed". You can't possibly know whether > passing a DateTimeImmutable is safe without reviewing the code on all the > call hierarchy starting from where your DateTimeImmutable is passed. > > > unless we create the >> inheritance, on the other side we have some code that modifies DateTime >> and should be protected from passing DateTimeImmutable - but there's no >> such code yet since nobody passes DateTimeImmutable anywhere yet, so we >> don't make any problem for existing code. >> > > "[C]ode that modifies DateTime and should be protected from passing > DateTimeImmutable" DOES exist already. Saying that it's not a problem for > existing code because no one passes DateTimeImmutable is a misleading > statement -- it assumes codebases exist in isolation. But current libraries > that take DateTime will still be used in 5.5; in fact, that's the basis of > your whole argument for this choice. > > > I find it highly likely that majoirty of DateTime users don't care if >> it's mutable or not since they either don't change it (most frequent use >> case) or use something like $foo = $bar->modify("+1 day"); and never >> rely on the fact that $bar was modified. Of course, I have no data about >> how many but I find it highly likely that many users simply don't care >> about the difference. >> > > Here is some data: > > http://code.google.com/**codesearch#search/&q=%5C$date-** > %3Emodify%20lang:php&type=cs&**sq= > > As you can see, your assumption is false. In the majority of cases, there > is no assignment. > > -- > Gustavo Lopes > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d043be21c8f002804d624684d--