Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93280 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88647 invoked from network); 12 May 2016 16:37:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2016 16:37:32 -0000 Authentication-Results: pb1.pair.com header.from=m.perone@mvlabs.it; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=m.perone@mvlabs.it; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mvlabs.it from 62.149.202.251 cause and error) X-PHP-List-Original-Sender: m.perone@mvlabs.it X-Host-Fingerprint: 62.149.202.251 london.moltiplika.com Received: from [62.149.202.251] ([62.149.202.251:49814] helo=london.moltiplika.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/11-28272-B41B4375 for ; Thu, 12 May 2016 12:37:31 -0400 Received: from [192.168.1.199] (93-51-171-194.ip267.fastwebnet.it [93.51.171.194]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: smtp_mv@moltiplika.com) by london.moltiplika.com (Postfix) with ESMTPSA id 25256111AF0 for ; Thu, 12 May 2016 18:35:55 +0200 (CEST) To: internals@lists.php.net Message-ID: <5734B148.40602@mvlabs.it> Date: Thu, 12 May 2016 18:37:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Functorial interfaces From: m.perone@mvlabs.it (Marco Perone) Hi everybody, I hope this is the right place for asking such a question. If that's not the case, please excuse me; I'd appreciate if you could redirect me to the appropriate place. The PHP manual says, regarding Interfaces, that the class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error. I don't understand why this needs to be so. Consider for example the following case: I have an interface interface Foo { public function foo(SpecialClass $object); } and a class class Bar { public function foo(BaseClass $object) { // do something with BaseClass $object } } that has the same signature of Foo except for the fact that the method foo takes a BaseClass, where SpecialClass extends BaseClass. From a theoretical point of view, saying that a class satisfies the interface Foo means that it has a method foo that is able to deal with a SpecialClass object. So Bar satisfies the contract imposed by Foo since it has a method foo that is able to deal with a BaseClass, which means that it will also be able to deal with SpecialClass. Hence it would seem natural to say that Bar implements Foo. But, as the documentation says, this produces a fatal error. What is the reason for this fatal error? Is there a specific reason to do things this way? It this is the case, could you please provide an example that proves why my approach creates problems. Thank you