Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92530 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16631 invoked from network); 20 Apr 2016 09:46:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 09:46:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:47701] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/F5-14036-E0057175 for ; Wed, 20 Apr 2016 05:46:55 -0400 Received: by mail.experimentalworks.net (Postfix, from userid 1003) id A697D476A7; Wed, 20 Apr 2016 11:46:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on km31408.keymachine.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=4.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-HAM-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Received: from [192.168.2.34] (ppp-46-244-184-58.dynamic.mnet-online.de [46.244.184.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id A079D476A6; Wed, 20 Apr 2016 11:46:49 +0200 (CEST) Message-ID: <1461145606.7556.11.camel@kuechenschabe> To: Jesse Schalken Cc: Andrea Faulds , PHP internals Date: Wed, 20 Apr 2016 11:46:46 +0200 In-Reply-To: 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> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-1zXgZbypDCuWXnxRiQaF" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) --=-1zXgZbypDCuWXnxRiQaF Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 2016-04-20 at 17:57 +1000, Jesse Schalken wrote: >=20 > With unions: >=20 > function foo(Bar|string $b) { >=20 > if (is_string($b)) { > // ... > } else { > // I know $b is a Bar here. I don't need to check. :) > } > } I' still missing a real-life use case for this. There's no operation I can come up with which works with an object or string. Unions between object types should be handled via interface. The only relevant union types I found till now are array | Traversable array | Countable and eventually array | Offset[Get|Set] The last one is a bit critical due to the fact that arrays are value types, whereas objects are reference types so function ($a) { $a[] =3D 42; } behaves notably differently between objects and arrays. So that case might need some thinking. For the others instead of a generic union type I'd prefer a special array-solution. johannes --=-1zXgZbypDCuWXnxRiQaF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAABAgAGBQJXF1AGAAoJEH3sTmn8nIPXAhQH/iZdOgc/iyNHZlvJLRQ7Cwb+ ZHLZRo3Sfap53SJLqX4OkKxA1ALyAFOx66mVzVp419r8F4V+eAy32l88QZ/ri7R7 V7WY06O6W3AWTneOw/IncCxZhE1k+OH+jYcHLDSFZlL9HYkQdTukdIGXczhHGNp/ yAbl/CPydTY8sYRTkKZfmjmO3mXy9OI5i83+QeA8mV+kgDfV01fCGg9uqutLv13E vNclLcuqpJdZ3EeXcLp4WT4wwt1Pskc7VKDj6llVwR3T8wUh3sqfRPFRkyaSuepV Nc1T9d0Apb45HpMmdb0ZkYy/mSwhP91c7O0mqOcsvzuMOyPtUTWev9GRKScc3WU= =kKMc -----END PGP SIGNATURE----- --=-1zXgZbypDCuWXnxRiQaF--