Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65893 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47028 invoked from network); 16 Feb 2013 23:30:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Feb 2013 23:30:37 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.153 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.153 smtp153.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.153] ([67.192.241.153:55521] helo=smtp153.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/C1-32672-B9610215 for ; Sat, 16 Feb 2013 18:30:36 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp5.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 4C622584C8; Sat, 16 Feb 2013 18:30:32 -0500 (EST) X-Virus-Scanned: OK Received: by smtp5.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id D1E20584C0; Sat, 16 Feb 2013 18:30:31 -0500 (EST) Message-ID: <51201696.6080604@sugarcrm.com> Date: Sat, 16 Feb 2013 15:30:30 -0800 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: Nikita Popov CC: PHP internals References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Questions regarding DateTimeImmutable From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > a) The DateTimeImmutable class extends the DateTime class. Why was this > done this way? Both classes are incompatible (as in the inheritance They're not really "incompatible". Functions that do not modify dates would work just fine. So it's "not 100% compatible", which is not the same as incompatible. Of course, we could instead create DateTimeBaseAbstractClass, but IMHO rewriting all your code to support it wouldn't be worth the trouble for 99.9% of the code, so what would end up happening that nobody could use DateTimeImmutable with any existing code that expects DateTime. I personally don't see much point in DateTimeImmutable anyway (immutable data structures are very important for concurrent programs but for PHP I don't see much benefit) but if people need it, fine. But ask yourself a question - do you really want to rewrite every library that accepts DateTime as an argument in order to use DateTimeImmutable? > b) The DateTimeImmutable class is (method-wise) an exact copy of DateTime. > This makes for some rather weird method names for an immutable object. E.g. > there is DateTimeImmutable::modify, which to me seems quite contradictory. > There are also a lot of methods of the DateTimeImmutable::setTime form, > which also seems rather odd and confusing (how can I set something on an > immutable object?) I don't see how it's so hard to grasp - it sets time and returns the modified object. I can't believe you genuinely don't understand how it works. I have a feeling this "confusing" argument in getting somewhat stale: PHP users - especially those that want to use specially designed classes that are useable only in context of design of non-trivial complexity - have sufficient brain capacity to understand what setTime could do. And if they absolutely can't, they can to the unthinkable - read the manual. So I can see the LSP argument - but "confusing" argument really doesn't seem to apply here. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227