Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93281 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91006 invoked from network); 12 May 2016 16:47:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2016 16:47:15 -0000 Authentication-Results: pb1.pair.com header.from=andreas@heigl.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=andreas@heigl.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain heigl.org from 195.191.240.18 cause and error) X-PHP-List-Original-Sender: andreas@heigl.org X-Host-Fingerprint: 195.191.240.18 hos109.unaxus.net Received: from [195.191.240.18] ([195.191.240.18:50941] helo=hos109.unaxus.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/91-28272-193B4375 for ; Thu, 12 May 2016 12:47:14 -0400 Received: from tmo-113-107.customers.d1-online.com ([80.187.113.107]:14007 helo=wdv-hg-0C07-zX4090-HeiglAndreas.local) by hos109.unaxus.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.87) (envelope-from ) id 1b0tlW-002LOC-5G; Thu, 12 May 2016 18:47:10 +0200 To: Marco Perone , internals@lists.php.net References: <5734B148.40602@mvlabs.it> Message-ID: Date: Thu, 12 May 2016 18:47:09 +0200 MIME-Version: 1.0 In-Reply-To: <5734B148.40602@mvlabs.it> Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="------------ms070401090701090206070208" X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hos109.unaxus.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - heigl.org X-Get-Message-Sender-Via: hos109.unaxus.net: authenticated_id: a.heigl+heigl.org/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hos109.unaxus.net: a.heigl@heigl.org Subject: Re: [PHP-DEV] Functorial interfaces From: andreas@heigl.org (Andreas Heigl) --------------ms070401090701090206070208 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Am 12.05.16 um 18:37 schrieb Marco Perone: > Hi everybody, > I hope this is the right place for asking such a question. If that's no= t > the case, please excuse me; I'd appreciate if you could redirect me to > the appropriate place. >=20 > 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. >=20 > I don't understand why this needs to be so. Consider for example the > following case: I have an interface >=20 > interface Foo > { > public function foo(SpecialClass $object); > } >=20 > and a class >=20 > class Bar > { > public function foo(BaseClass $object) > { > // do something with BaseClass $object > } > } >=20 > that has the same signature of Foo except for the fact that the method > foo takes a BaseClass, where SpecialClass extends BaseClass. >=20 > 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. >=20 > Hence it would seem natural to say that Bar implements Foo. But, as the= > documentation says, this produces a fatal error. >=20 > 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 >=20 Hey Marco. It's the other way around. The interface creates a contract that ensures that you can use ALL methods available in your SpecialClass. But that might be more, never less methods than in BaseClass. So when you try to call methods of the SpecialClass while executing Bar::foo() (which you have a contract on) it might fail as BaseClass might not have those methods. class BaseClass { public function a(){} } class SpecialClass extends BaseClass{ public function b(){} } Think about the implementation of your class Bar: class Bar implements Foo { public function foo($x){ $x->b(); } } So calling (new Bar())->foo(new BaseClass()) will fail as the method 'b' isn't implemented, but it should be according to the interface... Hope that helps ;) Cheers Andreas --=20 ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:andreas@heigl.org N 50=C2=B022'59.5" E 08=C2=B0= 23'58" | | http://andreas.heigl.org http://hei.gl/wiFKy7 | +---------------------------------------------------------------------+ | http://hei.gl/root-ca | +---------------------------------------------------------------------+ --------------ms070401090701090206070208 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCC BawwggWoMIIDkKADAgECAgMPT+kwDQYJKoZIhvcNAQENBQAweTEQMA4GA1UEChMHUm9vdCBD QTEeMBwGA1UECxMVaHR0cDovL3d3dy5jYWNlcnQub3JnMSIwIAYDVQQDExlDQSBDZXJ0IFNp Z25pbmcgQXV0aG9yaXR5MSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0QGNhY2VydC5vcmcwHhcN MTQwNzIzMDkzMjQ5WhcNMTYwNzIyMDkzMjQ5WjBcMRYwFAYDVQQDEw1BbmRyZWFzIEhlaWds MSAwHgYJKoZIhvcNAQkBFhFhLmhlaWdsQGhlaWdsLm9yZzEgMB4GCSqGSIb3DQEJARYRYW5k cmVhc0BoZWlnbC5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCn6XLcWFLD vAXgllUikBAU2Rv63m7ZKP+ZU/2HTWDW0BJ2muK7GD3cGZxbKKosO6l6PSqqmLqUJ8G6b/85 iPQmNL5z+LG/+wt/p31SOMAWc5UA7CJAQ9pivUCcV+Yt0LzoxWO5ME2rEZ/ioB2tXMilkJLM U4f5A9m3YZVSKj3xbM7rIpQEZiK0TrZ4MchTwPMdAwBLBxCoAztcg4Yj4qKd+IQLff0Ldhc5 3tc9b+XT7YzWLY5rQKHE+hKqIAdvYfqqKQZFHBBXptSXUXBeYK5a4UT0fpnMP7toqr/9mLlK +FvDNeVwSo5I/abiqdek1lH0/xwYy9im8k4SRtLTAp7hAgMBAAGjggFUMIIBUDAMBgNVHRMB Af8EAjAAMFYGCWCGSAGG+EIB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