Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65974 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5324 invoked from network); 19 Feb 2013 17:43:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2013 17:43:24 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.49 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.219.49 mail-oa0-f49.google.com Received: from [209.85.219.49] ([209.85.219.49:37778] helo=mail-oa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/D0-17768-BB9B3215 for ; Tue, 19 Feb 2013 12:43:23 -0500 Received: by mail-oa0-f49.google.com with SMTP id j6so7062094oag.8 for ; Tue, 19 Feb 2013 09:43:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=sU88gob3Ml5avuPhxl2WxWsO/iRuG71O1MVkOl6VY4A=; b=PASN7SV64fzq872NrZ9RejXQPQf61Ik6r9QhkHExUuuVomlP7G7ckblQsKj5tmPcmj IFa50rzNDPqZKHpCK3xOXXxE0gwr7AgRqoXtYJBnGUXpM8mHfEnA/gYrv2p/EFt5ecNZ f1fh8WDlcTEFBUi3u5FTf6BtCk1/kEN0fLzepM4jddUX7vVsqx+jJ2Psudgyr2z6gF2K Tk0Ijz6SSPWGfpGvsPBGpux9EgX2Th6frqHmIgVP1AlranEj/1xEneloIaztftc7FS8J mKV7dK65cDONeGVxrT9ZWBW/o3A4MEMPwFkI26xicGbQd8Ky43DYgEraYVE6ujPTjhJZ 2Iaw== MIME-Version: 1.0 X-Received: by 10.60.1.73 with SMTP id 9mr3794265oek.129.1361295800278; Tue, 19 Feb 2013 09:43:20 -0800 (PST) Received: by 10.76.24.234 with HTTP; Tue, 19 Feb 2013 09:43:20 -0800 (PST) In-Reply-To: References: Date: Tue, 19 Feb 2013 10:43:20 -0700 Message-ID: To: Derick Rethans Cc: Nikita Popov , PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Questions regarding DateTimeImmutable From: morrison.levi@gmail.com (Levi Morrison) >> a) The DateTimeImmutable class extends the DateTime class. Why was >> this done this way? Both classes are incompatible (as in the >> inheritance violates LSP). E.g. if you hint against DateTime, then >> passing in DateTimeImmutable will not work (as the behavior is >> different). The same also applies the other way around (DateTime >> extending DateTimeImmutable). Imho a mutable and an immutable variant >> of a class can't reasonably extend from one another, so I'm not sure >> why this was done. > > It was mostly done so that methods and code accepting do not need > signature changes. In many cases library code would accept a DateTime, > call modify and return the changed object - not realizing that the > original object was changed as well causes issues with calling code. By > having DateTimeImmutable extend DateTime they can continue to pass them > in, without having to change library code at all. What if they return the same object knowing that `modify` actually modifies the object? I personally would have done that except in the lucky situation that I used it in the return statement: return $timestamp->modify('+30 days'); Then I'd luckily work with DateTimeImmutable. --- While I personally think DateTime should have been immutable from the beginning, I don't think it's in PHP's best interest to try to fix this particular problem by introducing DateTimeImmutable.