Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81839 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84123 invoked from network); 4 Feb 2015 20:27:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2015 20:27:08 -0000 Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.170 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:36210] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/C7-40930-A9082D45 for ; Wed, 04 Feb 2015 15:27:07 -0500 Received: by mail-wi0-f170.google.com with SMTP id bs8so31573260wib.1 for ; Wed, 04 Feb 2015 12:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=4urKFJdDmwFnI7CqRcRuEkpoSGCXovn2esx+Ms81h4I=; b=hwI7ePYRU5hp1+YkuhQEEo/MMb0fE28/utqe3V9N52tEJp2XoEyGHhYNpqnAjgVkJD HSGCJDyJ5Ta4DrkpSfmKcdNxg/ronqtRC5pDl7cRTfDkB7zS1/eXbEkPQNvn0Qr/mrSl rP1QTXPJELh0Swndjkrp43b7K+VeDIBGQbCuSI/m0DsUI1R1ftRGmplymYMMQ+Qz6vaQ mViaS0gHz9y0Xt3qbk55IUC9FuRBN5n0oBq6AxFq+jnRyhDP6x8ylJQ1EZmAne0ngHu2 zOu6+0XxTemcxaPGZyCbkzC2m0hzvstixcnJ2XyEijddoN0WYdKN8AHhlEcwv2XtmOv0 HzCQ== X-Received: by 10.180.81.98 with SMTP id z2mr50450456wix.40.1423081622799; Wed, 04 Feb 2015 12:27:02 -0800 (PST) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.194.94.137 with HTTP; Wed, 4 Feb 2015 12:26:22 -0800 (PST) In-Reply-To: <54D27B45.5060200@gmail.com> References: <54D27B45.5060200@gmail.com> Date: Wed, 4 Feb 2015 21:26:22 +0100 X-Google-Sender-Auth: fuU96GkZImCggrhOeQGu1Hatl9M Message-ID: To: Rowan Collins Cc: PHP Internals Content-Type: multipart/alternative; boundary=f46d044288c89d0d4d050e490220 Subject: Re: [PHP-DEV] Allow dropping typehints during inheritance From: jpauli@php.net (Julien Pauli) --f46d044288c89d0d4d050e490220 Content-Type: text/plain; charset=UTF-8 On Wed, Feb 4, 2015 at 9:04 PM, Rowan Collins wrote: > 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) < > http://en.wikipedia.org/wiki/Covariance_and_contravariance_ > %28computer_science%29#Covariant_method_return_type> > > 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. > Whatever we choose, we must find a solution that is unique and spread into all the core language and core exts. And we have to think about BC : if we choose something more strict, we will generate more BC breaks for the switch to PHP7, which is not really a good thing. However, I'm all good for us to find a clear solution on type parameters, return types, extended type hints ... whatever other RFC will be accepted about this kind of subject. PHP7 should also be the moment we turn PHP into a more consistent, mature and professional language. And on the way to make the right choice, why not start by having a look at what other languages provide ? Julien Pauli --f46d044288c89d0d4d050e490220--