Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77294 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 265 invoked from network); 17 Sep 2014 15:02:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2014 15:02:43 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:37565] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/07-57031-292A9145 for ; Wed, 17 Sep 2014 11:02:43 -0400 Received: by mail.experimentalworks.net (Postfix, from userid 1003) id E367C421E8; Wed, 17 Sep 2014 17:02:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on km31408.keymachine.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.2 X-Spam-HAM-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Received: from [192.168.2.31] (ppp-93-104-26-154.dynamic.mnet-online.de [93.104.26.154]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id 83FDC421E8; Wed, 17 Sep 2014 17:02:46 +0200 (CEST) To: Christian Stoller Cc: "internals@lists.php.net" In-Reply-To: <4ED7146272E04A47B986ED49E771E347BBF1BAF541@Ikarus.ameusgmbh.intern> References: <4ED7146272E04A47B986ED49E771E347BBF1BAF541@Ikarus.ameusgmbh.intern> Content-Type: text/plain; charset="UTF-8" Date: Wed, 17 Sep 2014 17:01:27 +0200 Message-ID: <1410966088.3023.50.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Implementing interface method with child class in parameter def (Bug #42330) From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Wed, 2014-09-17 at 16:52 +0200, 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); > } Here you say "any A can be passed at argument" > class D implements C { > public function foo(B $b) { here you say "only a subset of A can be passed as argument" Thus having function bar(C $c) { $a = new A(); $c->foo($a); } might work or might not work as $c might be an instance of D. Thus breaks the Liskov Substitution Principle http://en.wikipedia.org/wiki/Liskov_substitution_principle doing it the other way round would work interface E { function foo(B $b); } class F implements E { public function foo(A $a) { } } as any B satisfies the is-a requirement compared to A, so everything valid for E::foo() is valid for F::foo(), too. Along with other subtypes to A. johannes