Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77293 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97968 invoked from network); 17 Sep 2014 14:57:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2014 14:57:20 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.47 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.219.47 mail-oa0-f47.google.com Received: from [209.85.219.47] ([209.85.219.47:48607] helo=mail-oa0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 41/86-57031-F41A9145 for ; Wed, 17 Sep 2014 10:57:20 -0400 Received: by mail-oa0-f47.google.com with SMTP id g18so1225314oah.20 for ; Wed, 17 Sep 2014 07:57:17 -0700 (PDT) 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; bh=QWsj5OKxtW5sEqMOZcegVevvK4dp9+fvzX3uhcpWRgU=; b=nco+AL5NlUfpkodiJUVo16jZSGRE4hK1ZfJOZee2Wdki1S0OBYjfXDBwHxmtqsz1Xi p7HrAWM1RzO+WHJ42iKy1qTMKQ/InCpHvdk7oLWGpYGHhG2A2pvr1WzFLrBDSvUCBPhh Np8jXONOI49wC9zKyGHweI858R15t/I9HFY9E3IR1sXyo2jeMQfAEmqvfNfoHbrAzW9l 68RleEMS/6vsvOn9x5uqgL5rtMzWMjE2C+JbnyIWNRhU69ws3vjZq7B9kj+kj3DhtYS6 oS4eXFK8326lTFPYWr3m3Pd47QxlqVfXkIbU7vpDJEYjG3t+fwTAaQW362tqc6PRdksK MEig== MIME-Version: 1.0 X-Received: by 10.182.66.16 with SMTP id b16mr9972960obt.49.1410965837589; Wed, 17 Sep 2014 07:57:17 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.76.106.20 with HTTP; Wed, 17 Sep 2014 07:57:17 -0700 (PDT) In-Reply-To: <4ED7146272E04A47B986ED49E771E347BBF1BAF541@Ikarus.ameusgmbh.intern> References: <4ED7146272E04A47B986ED49E771E347BBF1BAF541@Ikarus.ameusgmbh.intern> Date: Wed, 17 Sep 2014 08:57:17 -0600 X-Google-Sender-Auth: AosVMG_pNFc3sdLtAYIlzhvjM_s Message-ID: To: Christian Stoller Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Implementing interface method with child class in parameter def (Bug #42330) From: levim@php.net (Levi Morrison) On Wed, Sep 17, 2014 at 8:52 AM, Christian Stoller wrote: > Hello all, > > I hope the subject is not misleading. Please look at the following code: > > class A { } > > class B extends A { } > > interface C { > function foo(A $a); > } > > class D implements C { > public function foo(B $b) { > > } > } > > This code produces a "Fatal error: Declaration of D::foo() must be > compatible with C::foo(A $a) in /xyz/inheritance.php on line 10" > (see http://3v4l.org/l2M0f). > > I don't get the reason for that behavior (and I could not find any > documentation about that, at least not at > http://php.net/manual/en/language.oop5.typehinting.php). > > I have already found https://bugs.php.net/bug.php?id=42330 but Derick's > response does not help me and the linked file cannot be accessed > anymore. > > I'd say that it is absolutely legal to define a more specialized > type in a child or implementing class, or would this have any bad > side effects? This is because parameters are not covariant, they are usually invariant or contravariant. Almost certainly you have no clue what that actually means; it's okay, most people don't. Just go read and learn about them and learn for yourself why parameter types are not covariant.