Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66040 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68877 invoked from network); 20 Feb 2013 09:47:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2013 09:47:33 -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.170 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:44801] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/59-19387-4BB94215 for ; Wed, 20 Feb 2013 04:47:32 -0500 Received: by mail-we0-f170.google.com with SMTP id z53so6612883wey.29 for ; Wed, 20 Feb 2013 01:47:29 -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=zl0sYNF0ac2/80HDVFQFhZfTFGaNz3IjA+SWNcTm2VA=; b=DzO2K9MJXhJmptLp27AOBkzDHIROmA9qWJjgHacmyw29YAn+HIiPpCALSEohQsIglW xHFoNKl3ixM4Xi0gSqKdvcOkMVziHUssGnR4GPbmt6xFhOL5Mit2xFgEdkcJ2Mf957b3 RwpcKhuCkE3uoG0mJ/EnEmG97GjX92l04L4uqivgmzGnGnFZX2u7Lnnwu8WGiwh0m9PH fjPnPFMZIESH3wr+FWhExs7YPqzM66xl26cJUlmD8pD8efesE386u3vxjleJoSxjY3Ko 5A9uYAJcaAFv7K25GI3Jz3mZOPgMt+W5p3/qr4Yl0cJyRzCjjiZZcWmtrp1vvByRnyBP gHJQ== MIME-Version: 1.0 X-Received: by 10.180.105.67 with SMTP id gk3mr30977881wib.31.1361353649461; Wed, 20 Feb 2013 01:47:29 -0800 (PST) Received: by 10.194.5.233 with HTTP; Wed, 20 Feb 2013 01:47:29 -0800 (PST) X-Originating-IP: [77.11.89.24] In-Reply-To: <51249818.2040308@sugarcrm.com> References: <1867201214.20130215192512@cypressintegrated.com> <51248C24.4070609@sugarcrm.com> <51249818.2040308@sugarcrm.com> Date: Wed, 20 Feb 2013 10:47:29 +0100 Message-ID: To: Stas Malyshev Cc: Gustavo Lopes , Derick Rethans , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d04426a22b0987004d624d814 X-Gm-Message-State: ALoCoQlCjfK4FCFgWgOpqaYvvOEmJBsWkNGtSlDj00PzEKBltdvSPMSV6/KslMLyJEP2wBi9+8ey Subject: Re: [PHP-DEV] Questions regarding DateTimeImmutable From: kontakt@beberlei.de (Benjamin Eberlei) --f46d04426a22b0987004d624d814 Content-Type: text/plain; charset=ISO-8859-1 People are not using modify() in this way, because they have been bitten before I would suppose. What i find important about the DateTime vs DateTimeImmutable is the expectations I have with regard to how they work with internal state. If i have a typehint for DateTime, i clone the object before working on it. If I have a typehint for DateTimeImmutable, i just start using it. This means the usage patterns for both objects will look very different. Also for example, the following code is not possible without instanceof checks: function thirtyDaysLater(DateTime $dt) { $later = clone $dt; $later->modify("+30 day"); return $later; } If i pass a DateTimeImmutable in there, the code will not work. Imho its not about people are not using it this way in open source code, its about creating a very likely source of bugs of the ugly to debug kind. On Wed, Feb 20, 2013 at 10:32 AM, Stas Malyshev wrote: > Hi! > > > 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. > > If I know what the code does with dates, I don't need to review it. > > > 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. > > This is true. That's why I want to see what is more probable - that > library accepts DateTime and would be fine with DateTimeImmutable or > that library accepts DateTime and would have to be rewritten to work > with DateTimeImmutable. > > > 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. > > This isn't really a good data since most of this code creates its own > DateTime and thus there's very little relevancy to what we're talking > about. If you look up the functions that actually accept DateTime: > > > http://code.google.com/codesearch#search/&type=cs&q=DateTime%5Cs%5C$%20lang:%5Ephp$ > > the picture would be quite different. I scanned through first 5 pages > and couldn't find a function that actually calls modify() on DateTime > object it receives. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d04426a22b0987004d624d814--