Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81841 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96948 invoked from network); 4 Feb 2015 21:18:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2015 21:18:24 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.174 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.174 mail-wi0-f174.google.com Received: from [209.85.212.174] ([209.85.212.174:35999] helo=mail-wi0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/2A-40930-F9C82D45 for ; Wed, 04 Feb 2015 16:18:23 -0500 Received: by mail-wi0-f174.google.com with SMTP id n3so34851944wiv.1 for ; Wed, 04 Feb 2015 13:18:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=wgUc1zltNwCd3l6GAniEmqUEJa/acRu3p9y8aZH5LBI=; b=SrE9fdmq7zgXbvHCNfoD0v0huFnH0DPoVHqogHxbKCyuIukJiLy23Nv4OOjBeNMOOc 7dD9XfPvzhdcXJyZxCxKKeikORhtixuFYiO+lm3suguFgG/Amt9ezUSAKyLGZPULzQXY 5tVsoF5jJBEwV1dWpO3TA+TpxjZhiAzjrn9TNuOFcMwD4mT6a11khNPMnnQGkNeNDRPK POyNMA2M9Lb9RLp8fZTuELeeZ+YOJ3KNhJiW2zPJF3RIjQ6Q3I3bxkndSVrBGBtPen0J qX8+UBeXOCCjsNLrXCxIHUIkxDyxo+cQv45u8u1KZWLMNedXc9+AqvD0oNa9OMUOIMHR xaZg== X-Received: by 10.180.210.172 with SMTP id mv12mr6144152wic.64.1423084698403; Wed, 04 Feb 2015 13:18:18 -0800 (PST) Received: from [192.168.0.3] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id d6sm4918459wic.1.2015.02.04.13.18.17 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Feb 2015 13:18:17 -0800 (PST) User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Wed, 04 Feb 2015 21:17:14 +0000 To: PHP internals Message-ID: <73F87BE7-E57C-4275-A435-98C39A751E87@gmail.com> Subject: Re: [PHP-DEV] Allow dropping typehints during inheritance From: rowan.collins@gmail.com (Rowan Collins) 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.) -- Rowan Collins [IMSoP]