Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81838 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81724 invoked from network); 4 Feb 2015 20:05:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2015 20:05:36 -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.175 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.175 mail-wi0-f175.google.com Received: from [209.85.212.175] ([209.85.212.175:40888] helo=mail-wi0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/67-40930-E8B72D45 for ; Wed, 04 Feb 2015 15:05:35 -0500 Received: by mail-wi0-f175.google.com with SMTP id fb4so34424003wid.2 for ; Wed, 04 Feb 2015 12:05:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=KfHqBTRBTl/Qg58TjZCQxWABz2rd7uFRVurxxcUq1uU=; b=WgO/aiyJLAd2z3xyYJGo/MzFyPbdGaPcBxwYp38240z80PnQHl39BX73ATxY9kJQKQ gBKaXwQFJnfpamNRscbGCLjsn9/tY3y09/1PpViCawqg2bwELMpgDRJwYyaB8vDp8ak8 hmz/d4D2w8+HLbdrlsBKUiCNCjVGOaX60CY6d1cm8ipYjXS8Da3GphaDQXdkXgzMZxs/ 633/ySsLPphfIzFmGZ5MCp9wWwkfL+QnkWKfiYbmg5uU9T+39HECUo9hWTJo6Viz8x+V x+JwyLZIj3gFxptT480VVeN10J/5DhlowwnyndRb7if36VDai+tI0eeBuQbuUfE76YXp rtiQ== X-Received: by 10.180.77.39 with SMTP id p7mr48723667wiw.8.1423080327323; Wed, 04 Feb 2015 12:05:27 -0800 (PST) Received: from [192.168.0.172] ([62.189.198.114]) by mx.google.com with ESMTPSA id d10sm4123282wjn.45.2015.02.04.12.05.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Feb 2015 12:05:26 -0800 (PST) Message-ID: <54D27B45.5060200@gmail.com> Date: Wed, 04 Feb 2015 20:04:21 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------090709030507040802090504" Subject: Re: [PHP-DEV] Allow dropping typehints during inheritance From: rowan.collins@gmail.com (Rowan Collins) --------------090709030507040802090504 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Nikita Popov wrote on 04/02/2015 18:49: > Hi internals! > > 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. For those that missed it, or have forgotten, there was a discussion of covariance and contravariance in November, kicked off by Levi's concerns over return type hints: http://grokbase.com/t/php/php-internals/14bstfz0pg/rfc-discussion-return-type-variance-checking In particular, this Wikipedia article explains the concepts very well (although once you get into generics it all gets a bit complicated, and irrelevant to us right now): http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science) Removing the typehint is a special case of contravariance, because it means "accept any type", and parameter contravariance in a nutshell is "a child implementation must accept at least what the parent accepts, but may also accept more". The current situation (invariance) is quite intuitive - the signatures must match - and full contravariance can be explained fairly easily - "B:method must accept all values accepted by A::method". My worry is that people won't understand why this particular special case is allowed, and may think PHP is just letting them be sloppy and remove other people's type hints. The other thing to consider is whether the same special case should be added (in reverse) to return type hints - a sub-class could *introduce* a return type hint, as long as the parent class did not already declare one. Regards, -- Rowan Collins [IMSoP] --------------090709030507040802090504--