Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81908 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57794 invoked from network); 5 Feb 2015 12:15:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 12:15:12 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.208 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.208 imap2-3.ox.privateemail.com Received: from [192.64.116.208] ([192.64.116.208:60410] helo=imap2-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/E5-27691-ACE53D45 for ; Thu, 05 Feb 2015 07:15:11 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 147858C0082; Thu, 5 Feb 2015 07:15:02 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id oI5fkRH1MDfq; Thu, 5 Feb 2015 07:15:01 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 2B5F58C007D; Thu, 5 Feb 2015 07:15:01 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: Date: Thu, 5 Feb 2015 12:14:58 +0000 Cc: Hannes Magnusson , Nikita Popov , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <4A36329B-F17B-4665-A84E-D8CF01F5B29A@ajf.me> To: Julien Pauli X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] Allow dropping typehints during inheritance From: ajf@ajf.me (Andrea Faulds) Hi Julien, > On 5 Feb 2015, at 12:10, Julien Pauli wrote: >=20 > If we allow larger type, why doesn't such code work ? >=20 > interface A { } > interface B extends A { } >=20 > class C { > public function foo(A $a) { } > } >=20 > class D extends C { > public function foo(B $a) { } // E_STRICT > } > =20 > This is wrong IMO. Well, firstly that=E2=80=99s the wrong way round: inheriting classes can = only *increase* the range of supported values, but you=E2=80=99ve done = exactly the opposite. But even if you fixed your code, you=E2=80=99d still have an error. This = ispresumably because doing anything other than simple invariance causes = enormous problems related to compilation order and autoloading, as we = discovered with the Return Types RFC. I think that we=E2=80=99d probably = support full contravariance for parameters if we could. However, we could easily support contravariance in type hint existence, = as that doesn=E2=80=99t require subclassing checks. -- Andrea Faulds http://ajf.me/