Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92311 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69391 invoked from network); 14 Apr 2016 19:25:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2016 19:25:30 -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.163 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.163 mx207.easyname.com Received: from [212.232.25.163] ([212.232.25.163:34659] helo=mx207.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/90-64966-9AEEF075 for ; Thu, 14 Apr 2016 15:25:29 -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 1aqmtI-0003QN-6i; Thu, 14 Apr 2016 19:25:24 +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> To: Stanislav Malyshev , internals@lists.php.net Message-ID: <570FEE98.1030401@fleshgrinder.com> Date: Thu, 14 Apr 2016 21:25:12 +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: <570FE8A9.4020809@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TkdFuUQp4TxMB78l7FoCjqeIQ98N6C9Hs" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: php@fleshgrinder.com (Fleshgrinder) --TkdFuUQp4TxMB78l7FoCjqeIQ98N6C9Hs Content-Type: multipart/mixed; boundary="O4NbGNmVCnq4UJGSV4oWwwH3srqucEqmw" From: Fleshgrinder Reply-To: internals@lists.php.net To: Stanislav Malyshev , internals@lists.php.net Message-ID: <570FEE98.1030401@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> In-Reply-To: <570FE8A9.4020809@gmail.com> --O4NbGNmVCnq4UJGSV4oWwwH3srqucEqmw Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/14/2016 8:59 PM, Stanislav Malyshev wrote: > Hi! >=20 >> I don't know what is complicated about "string|Stringable" or "Foo|Bar= " >> since it is super self-explanatory. However, I find myself checking th= e >=20 > It may be self-explanatory for you. It's much less self-explanatory for= > 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 string= > 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) but= > please remember it's a language with literally millions of use cases an= d > users. >=20 Reduce assertions*, enhance self-documentation, making code more robust, perform checks in the VM and not in userland, ... function fn($arg) { assert('is_string($arg) || method_exists($arg, "__toString")'); } interface Stringable { function __toString(): string; } function fn(string|Stringable $arg) { // :) } You can find more information on the topic here: https://en.wikipedia.org/wiki/Tagged_union * Assertions in PHP are very error prone if combined with refactoring due to the fact that one should enclose the actual assertion in a string.= --=20 Richard "Fleshgrinder" Fussenegger --O4NbGNmVCnq4UJGSV4oWwwH3srqucEqmw-- --TkdFuUQp4TxMB78l7FoCjqeIQ98N6C9Hs 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+6bAAoJEOKkKcqFPVVrwlUP/0chhuQJauUM72CrKwxtereG MrL+UZwtzT4q7JiQfg0AFE5dgOQ8AQkq7I5TBbuEKpUcf/9+jkoTiAECkNzLlvPU aztPE4ssdcwKBq2ANeL+ziNHVprsKQ9Nq3rGNm+Nb02B1tFETGSBsLkm4u6+jCPi 9JgCCzuXM5k/6tnSWTD1l8N6StDKJfzbid0Sulhcr8sdJpKjFK1zhuzS2PNYK2Cz 3nZ3EdAXe2HJDRPgBsL/2g9z9zhNBNKKwRC92cvLiysFGo+mCNluUMOI6lryjuUt C5tw3rn+Ai/Z1pCvusloXvgsP95HqUGnKUVv6Nn1dArMeKGOnykWdhLzHDEKn73y 7QMHY0/PZQ/MBdHK3O2pER22UsCzXQCZFjcCg8gIi8eFAisEqmufpkEUfCafI8NM E1eUSOYWBFjcjOUFBr6l8YpwphdIt3nbtWAJTzZ3f1plopsRwCi4oGcSuvDslfi3 d6MDIaylwuL0/wUx/AxHwuo500cL41gJl2O11I2TvZuuJgQvm9DGDtecf8D4eh6I X6EcGb6zKdqtjBdE5fTfE752gqFHYSaqQN5wo75Gv4wI8w0Gh8cllvu12TP1SCv6 xNfMf0AQ+7WYU5xMG9Jl1ttqkbU0hFmkzZSzdeBVyO4YCy7uSDNHN56+UWpxxIpG Pt5ZPVO4RqNUW8gSzEqQ =VDyP -----END PGP SIGNATURE----- --TkdFuUQp4TxMB78l7FoCjqeIQ98N6C9Hs--