Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81842 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3674 invoked from network); 4 Feb 2015 21:25:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2015 21:25:54 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wg0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:60366] helo=mail-wg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/9B-40930-06E82D45 for ; Wed, 04 Feb 2015 16:25:53 -0500 Received: by mail-wg0-f41.google.com with SMTP id a1so4209297wgh.0 for ; Wed, 04 Feb 2015 13:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=rMbEpFiuAueUCJGPjsDkUDq0gFWgFQerFDfuMWa4Pck=; b=EXCed4i8/X7MYORijZi4uouPRyhmTxyHBT59BqDCMqhEMqNgNQkSZS9h+vUx1Tvq7i oIKnMUzUB3rO3tAWaiBMaCDTkZFMY1F34cgxpHfKg3NQ9QRrWYMFPsqIuyOP08lEaCrx G2Ub8M3CES2Jg576QFdqZDOxkNCLYw3ZNcChY6tWGmFxjMQURuUr685n1nAkSsm8+k2R ttrEz6UzqG0PypqI5XxWPoGnpVM5dKkuVcsy2sVsZMZPRWc01DnJApizIQLUU4meXW4/ mz/vBCMZv+JUj05HkvbFAZsFTPGfQi1ZUFqcyJjak5SQt/r3dX1nagMkSE+imy4W7c8u lLkQ== MIME-Version: 1.0 X-Received: by 10.194.187.235 with SMTP id fv11mr922554wjc.16.1423085149903; Wed, 04 Feb 2015 13:25:49 -0800 (PST) Received: by 10.27.10.138 with HTTP; Wed, 4 Feb 2015 13:25:49 -0800 (PST) In-Reply-To: <73F87BE7-E57C-4275-A435-98C39A751E87@gmail.com> References: <73F87BE7-E57C-4275-A435-98C39A751E87@gmail.com> Date: Wed, 4 Feb 2015 22:25:49 +0100 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7bdcab84d86033050e49d41b Subject: Re: [PHP-DEV] Allow dropping typehints during inheritance From: nikita.ppv@gmail.com (Nikita Popov) --047d7bdcab84d86033050e49d41b Content-Type: text/plain; charset=UTF-8 On Wed, Feb 4, 2015 at 10:17 PM, Rowan Collins wrote: > On 4 February 2015 21:02:30 GMT, Yasuo Ohgaki wrote: > >Hi Nikita, > > > >On Thu, Feb 5, 2015 at 3:49 AM, Nikita Popov > >wrote: > > > >> Currently we do not allow [1] removing a typehint during inheritance. > >For > >> example the following code is not valid: > >> > >> interface A { > >> public function method(Typehint $param); > >> } > >> class B implements A { > >> public function method($param); > >> } > >> // Fatal error: Declaration of B::method() must be compatible > >with > >> A::method(Typehint $param) > >> > >> The above code does *not* constitute an LSP violation, because > >B::method() > >> accepts more inputs than A::method(). However we still forbid it. > >> > >> This is an issue, because it makes it impossible to add typehints to > >> parameters at a later point in time. I've seen this issue come up > >both in > >> userland code, as well as in a recent DateTime change, see > >> > >> > > > https://github.com/php/php-src/commit/8e19705a93d785cd1ff8ba3a69699b00169fea47 > >> . > >> > >> Instead of reverting the DateTime BC break, I'm wondering if it > >wouldn't be > >> better to fix the root cause by making the inheritance check less > >strict > >> and allow removing typehints? > >> > > > >I can understand your reason. It's reasonable perfectly. > >Template is better, but PHP is weakly typed language. > >I think it's acceptable. > > > >Since Dmitry agreed to introduce DbC, if he like the syntax, etc and > >proposal is passed. > >DbC may be used to check various types or user may simply write code > >that > >handles > >various types in function body. > > This is actually my fear: that people will misunderstand this as an excuse > to write invalid type checks, such as ones which are tighter rather than > looser than the parent class (it takes a bit of careful thought to > understand why this is wrong). Unfortunately, we don't have a keyword for > explicitly allowing any value, or even a base for all objects, so I guess > we have to take that risk, but at least if contravariance were fully > supported, we could have clear examples of correct usage. > > (Incidentally, I'm not sure how templates are relevant - this is purely > about inheritance and LSP of ordinary objects.) > > Maybe I wasn't clear here. I do not propose to allow any code that violates LSP. You will not be able to add a parameter typehint if the parent doesn't have one and you will not be able to change a typehint to a different class. I'm only proposing to support parameter contravariance to the limited degree we are capable of implementing currently. Nikita --047d7bdcab84d86033050e49d41b--