Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81966 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71025 invoked from network); 5 Feb 2015 21:52:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 21:52:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.171 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.171 mail-ob0-f171.google.com Received: from [209.85.214.171] ([209.85.214.171:45946] helo=mail-ob0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/1C-27691-906E3D45 for ; Thu, 05 Feb 2015 16:52:10 -0500 Received: by mail-ob0-f171.google.com with SMTP id gq1so9667470obb.2 for ; Thu, 05 Feb 2015 13:52:06 -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:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=ACldEDaxFNN3OVVIOXFiN282wH3cgBmsrKyZs+xLVZU=; b=S2aXDqk66DTSY/YXPqtddIa6hQq1olOsHQlG0MD3vqovjxVVGOeDa0kQLBO2f3G1dS Vfn9c6exnIxVJ7Ugvv85NFEtuTWU+dvNi9prFl7MNHEUEBAVfy/TX4djGVkYmAaSsnb8 Esf/OTNRZd+DJK35dpQZOIRgUZgTNnRvcQwkuLxkuA4fONo8cXpuJ6wnNMyBnhZVFBk8 2b+kzMN20uJDmdtivTNLXc4iF6ZUVZjG8OGOxJu+AJ+zjJFnP2tSWXML0RTj4LCP0Rs3 0oTmFVQyE06UQ4RxNF6g0umzsBe8OpxZ9QrYUoeqVXfCoIZqZ5P9jOTgwvFgep4csXn1 DAHg== MIME-Version: 1.0 X-Received: by 10.202.178.131 with SMTP id b125mr205569oif.80.1423173126871; Thu, 05 Feb 2015 13:52:06 -0800 (PST) Sender: morrison.levi@gmail.com Received: by 10.76.103.37 with HTTP; Thu, 5 Feb 2015 13:52:06 -0800 (PST) In-Reply-To: References: <4A36329B-F17B-4665-A84E-D8CF01F5B29A@ajf.me> Date: Thu, 5 Feb 2015 14:52:06 -0700 X-Google-Sender-Auth: pIfNAvY9W4br6jKuju_hwr7pz7g Message-ID: To: Andrea Faulds Cc: Julien Pauli , Hannes Magnusson , Nikita Popov , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Allow dropping typehints during inheritance From: levim@php.net (Levi Morrison) On Thu, Feb 5, 2015 at 5:14 AM, Andrea Faulds wrote: > Hi Julien, > >> On 5 Feb 2015, at 12:10, Julien Pauli wrote: >> >> If we allow larger type, why doesn't such code work ? >> >> interface A { } >> interface B extends A { } >> >> class C { >> public function foo(A $a) { } >> } >> >> class D extends C { >> public function foo(B $a) { } // E_STRICT >> } >> >> 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 exac= tly 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 eno= rmous problems related to compilation order and autoloading, as we discover= ed with the Return Types RFC. I would hardly call them "enormous problems". Just normal problems that I think were easier to avoid than to deal with given my schedule and the time-frame for PHP 7. To chime in regarding allowing contravariant parameter types: I struggle to find use cases for it. I can only think of one use-case and it's flawed: when something has declared an Iterator parameter and you widen it to include Traversable. However, even though Traversable is a parent of Iterator you can't directly call iterator methods on it, so it could break the calling code despite the super-type check passing.