Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92477 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2425 invoked from network); 19 Apr 2016 17:33:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 17:33:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.84 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.84 mx103.easyname.com Received: from [77.244.243.84] ([77.244.243.84:56768] helo=mx202.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/52-22821-8DB66175 for ; Tue, 19 Apr 2016 13:33:12 -0400 Received: from cable-81-173-133-226.netcologne.de ([81.173.133.226] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1asZWO-0000AB-Nd; Tue, 19 Apr 2016 17:33:08 +0000 Reply-To: internals@lists.php.net References: <570E99AC.3090804@fleshgrinder.com> <570EA5EB.8090501@fleshgrinder.com> <570EAB0D.6080706@gmail.com> <570EB67E.8010908@garfieldtech.com> <5B147E88-CC0A-4CBC-A49D-C7FE3BF557C0@zend.com> <6F.C3.12455.94C5F075@pb1.pair.com> <20160414094440.GF19347@phcomp.co.uk> <570FD94F.90703@fleshgrinder.com> <570FE8A9.4020809@gmail.com> <20.53.29891.17401175@pb1.pair.com> <57110BCD.5030009@garfieldtech.com> <571124C2.9040606@gmx.de> <57112F31.8070209@garfieldtech.com> To: Zeev Suraski , Larry Garfield Cc: "internals@lists.php.net" Message-ID: <57166BC9.8020602@fleshgrinder.com> Date: Tue, 19 Apr 2016 19:32:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gwLCTpFjDKXii3Ea39Pmob9wKVF58sTPk" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: php@fleshgrinder.com (Fleshgrinder) --gwLCTpFjDKXii3Ea39Pmob9wKVF58sTPk Content-Type: multipart/mixed; boundary="uQqluKqETrSmk7wBCGfts8pJBam8R0nMv" From: Fleshgrinder Reply-To: internals@lists.php.net To: Zeev Suraski , Larry Garfield Cc: "internals@lists.php.net" Message-ID: <57166BC9.8020602@fleshgrinder.com> Subject: Re: [PHP-DEV] Re: Improving PHP's type system References: <570E99AC.3090804@fleshgrinder.com> <570EA5EB.8090501@fleshgrinder.com> <570EAB0D.6080706@gmail.com> <570EB67E.8010908@garfieldtech.com> <5B147E88-CC0A-4CBC-A49D-C7FE3BF557C0@zend.com> <6F.C3.12455.94C5F075@pb1.pair.com> <20160414094440.GF19347@phcomp.co.uk> <570FD94F.90703@fleshgrinder.com> <570FE8A9.4020809@gmail.com> <20.53.29891.17401175@pb1.pair.com> <57110BCD.5030009@garfieldtech.com> <571124C2.9040606@gmx.de> <57112F31.8070209@garfieldtech.com> In-Reply-To: --uQqluKqETrSmk7wBCGfts8pJBam8R0nMv Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/19/2016 11:41 AM, Zeev Suraski wrote: > It could actually implement all of them - the two parents, and the chil= d. That sounds like a pretty good, explicit way that requires no introdu= ction of any new syntax, concepts or engine complexity in order to do wha= t you're describing. This works fine: >=20 > interface foo { function foo(); } > interface bar { function bar(); } > interface baz extends foo,bar {} >=20 > class impl implements foo, bar, baz { > function foo(){} > function bar(){} > } >=20 > function sth(baz $b){} >=20 `class impl implements baz {}` is actually already enough here because `baz` extends `foo` and `bar`. This is the only way to solve such situations right now but it does not help with primitive types. :( > One thing we could consider is adding some intelligence for these cases= , and for interfaces that only extend other interfaces (without adding ne= w signatures) - a class would be considered to implement that interface i= f it implements all of the 'parent' interfaces that the child interface e= xtends:=20 >=20 > class impl implements foo, bar { > function foo(){} > function bar(){} > } >=20 > function sth(baz $b){} <-- would work, as impl implements both foo an= d bar, and baz does nothing but extending those. >=20 > I'm not sure that's necessary, and believe the current mechanisms and s= yntax satisfy these use cases already, but it's probably a possibility. >=20 That sounds like runtime checked duck typing. This actually makes the type system less strict and might have horrific side effects and that is exactly the opposite of what union/intersection types are meant for: preventing this. Above code is the same as: function sth($b) { $b->foo(); $b->bar(); } It will definitely fail if something else is passed in but if it is `foo`, `bar`, or `baz` everything is fine. The problem is that any object that satisfies the implementation of the methods `foo` and `bar` would ultimately fulfill the contract here. function sth(foo&bar $b) {} This is a different situation because now we know that it is something that actually implements exactly those two interfaces. Including possible additional constraints like argument and return type hints. There might even be a documentation shipped together with them that the implementer should take care of honoring. The intersection type hint is much stricter in such cases. --=20 Richard "Fleshgrinder" Fussenegger --uQqluKqETrSmk7wBCGfts8pJBam8R0nMv-- --gwLCTpFjDKXii3Ea39Pmob9wKVF58sTPk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXFmvNAAoJEOKkKcqFPVVrQtwP/0AkxFCuiyedlPAj4Nv7W7bN CUCa7nNJ40c3PE8jFkQIQ6rcnryl7106wQhYyp15vlcHWKaTqW2TWjwtVT22BSJr /m4dpX9wf/jAYm62pGJM0m6gpm0us/nRjTIOOAWDO6mQTZE0dF0li1pYUqNt7ws7 eEN31McrzZnp9Cu2SBsUBQdZk5vokI/292CiRMs5qTEpA1jmeWn44TDAZYRFqkej uuRrhFu3v/J0tfHZEio+eYdDB4NVfZ4qA35ivfHC+6MZQLj4MYXjUzwBE0c58cHO /8h6Ku5aKeJN3f7mG1ksk9uVqhMged4UR988HYWVZt3b1oDBNR0H49sPge0yAx7/ cVn1HR9WerMjxZUfuY4WXTQXPRGW+/1Nh8wZhWu+FchElYqv6mZIjJONGQltxod8 WLwqR0/03bUxNUhYG3Y6S/8IpGqA18m9HxhoRBxYWfybd5Sy4zEKiN9zsr03S23s SrSnWvszN7SCDVxKbHqhxCuiz4NkdB1rEny9YLYPJAViaZadR6x9wyVChoTUQJvK RYo2VydaX4ZUGF80TYYRLsh+GeqiaLsBQRNfE8e2mpajhlwvxxohoBNrMOIFev94 Dz7H0lMldhhRBLkTlkUnYbMUNahCB2FCozME/kikFN41sScz+LnMlQmMeQwqdvCb oI74/+kdgwA42cdLIvDg =p1iD -----END PGP SIGNATURE----- --gwLCTpFjDKXii3Ea39Pmob9wKVF58sTPk--