Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92312 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71039 invoked from network); 14 Apr 2016 19:28:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2016 19:28:01 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.166 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.166 mx210.easyname.com Received: from [212.232.25.166] ([212.232.25.166:34023] helo=mx201.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/01-64966-04FEF075 for ; Thu, 14 Apr 2016 15:28:01 -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 1aqmvj-0004An-UX; Thu, 14 Apr 2016 19:27:56 +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> <570FEE98.1030401@fleshgrinder.com> To: Stanislav Malyshev , internals@lists.php.net Message-ID: <570FEF32.2000107@fleshgrinder.com> Date: Thu, 14 Apr 2016 21:27:46 +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: <570FEE98.1030401@fleshgrinder.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="g8AjbqTeSBQBp8WDVnRiMsnP9KVRlsAiQ" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: php@fleshgrinder.com (Fleshgrinder) --g8AjbqTeSBQBp8WDVnRiMsnP9KVRlsAiQ Content-Type: multipart/mixed; boundary="BTXNFX1wXKfPAcfeb98eXfbeGkqiakXo8" From: Fleshgrinder Reply-To: internals@lists.php.net To: Stanislav Malyshev , internals@lists.php.net Message-ID: <570FEF32.2000107@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> <570FEE98.1030401@fleshgrinder.com> In-Reply-To: <570FEE98.1030401@fleshgrinder.com> --BTXNFX1wXKfPAcfeb98eXfbeGkqiakXo8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/14/2016 9:25 PM, Fleshgrinder wrote: > On 4/14/2016 8:59 PM, Stanislav Malyshev wrote: >> Hi! >> >>> I don't know what is complicated about "string|Stringable" or "Foo|Ba= r" >>> since it is super self-explanatory. However, I find myself checking t= he >> >> It may be self-explanatory for you. It's much less self-explanatory fo= r >> somebody just starting to learn. It is also very dangerous - if it's >> either Foo or Bar, can you call Foo::stuff on it or not? If it's strin= g >> or not string, can you call strlen on it? Etc., etc. It adds a lot of >> cognitive load and complicates the whole picture. You may have a >> specific use case where it is useful (which we have yet to see btw) bu= t >> please remember it's a language with literally millions of use cases a= nd >> users. >> >=20 > Reduce assertions*, enhance self-documentation, making code more robust= , > perform checks in the VM and not in userland, ... >=20 > function fn($arg) { > assert('is_string($arg) || method_exists($arg, "__toString")'); > } >=20 > interface Stringable { > function __toString(): string; > } >=20 > function fn(string|Stringable $arg) { > // :) > } >=20 > You can find more information on the topic here: >=20 > https://en.wikipedia.org/wiki/Tagged_union >=20 > * Assertions in PHP are very error prone if combined with refactoring > due to the fact that one should enclose the actual assertion in a strin= g. >=20 Oh oh oh, I forgot the very important unions *int|string* and *float|string* for overflows as one can encounter them from time to time; even in native code. --=20 Richard "Fleshgrinder" Fussenegger --BTXNFX1wXKfPAcfeb98eXfbeGkqiakXo8-- --g8AjbqTeSBQBp8WDVnRiMsnP9KVRlsAiQ 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 iQIcBAEBCAAGBQJXD+8yAAoJEOKkKcqFPVVrV7QP/RoNeE3y+9Pq2BIYDlG9pmNX YpAMfORzWo8V3ArBCh4i+Fl3qr4n5pOumrTFk2FwfgIKinj3AAD66eCVZSlS2yAK IXLZ5AxfEb44mJAMwA/ejGrG/A4EsRsHNupyRW9CcbevDo+QfsE4pt0OmB58TwKl 5TKw26HRGGFQ92MNoa1VAY1WlonV5Cq155ytASTOipWkGAxbZo74qLThEcq8AOzr U7xE5udycVp3ki7VDVJ/LoSHnA0jW0D+1qNM/sM0jjbRVlbczF6Dvwh8Sf7Y8UuA wUc4qrG163JV6Ub+XLeje+d4twZxLwR0qR3pZRgcArRGgo+I+kKhNwzQ1lk7Cl08 Cfrup9qktCFjTx4a+8CSmfaEUEzz+V1jEkVYVQ2CMzTE6A7DXBrP+BE1p3nPgmyf tfIMNUr0y3vQdco1Mj/q49TbF8mS9qlZ4gBFukHm+ST62cw7AXrZ0Rwd50MA95dt gPvWnWEc+GLYqUzmdfp3t4JXf8pQDtnMJ2T5j3WPww2pVw9xZ8eb/Z1gX42Cq9rP VNGXTtbxX2hT3cOI9wQEdZSjNm4CvWv004XU0xeN7FnOo7hJYKHbmof+IDDhTg6n LUEUIsaAS32pmuuvgAeQTnnug8YjRpaB1nPSQ6gGjIMoVA+vcUstMB8EOX2fBBJn f2PXptO9rC0CkRrm3tso =UmTN -----END PGP SIGNATURE----- --g8AjbqTeSBQBp8WDVnRiMsnP9KVRlsAiQ--