Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93759 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26114 invoked from network); 3 Jun 2016 21:31:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2016 21:31:51 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.105 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.105 blu004-omc2s30.hotmail.com Received: from [65.55.111.105] ([65.55.111.105:56600] helo=BLU004-OMC2S30.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/00-25194-647F1575 for ; Fri, 03 Jun 2016 17:31:51 -0400 Received: from BLU436-SMTP130 ([65.55.111.72]) by BLU004-OMC2S30.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Fri, 3 Jun 2016 14:31:48 -0700 X-TMN: [ULNDaf8pDQfcr35lyNwp3PDNz1qxvkB9] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_2B879295-0513-465E-8F51-A35B5522569B" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <5751B50F.2090003@garfieldtech.com> Date: Fri, 3 Jun 2016 23:31:43 +0200 CC: internals@lists.php.net References: <0A.C5.62101.1C860575@pb1.pair.com> <68b821ac-d71f-4be5-8dca-ae94db332630@gmail.com> <20160603101659.D466A1A81FC5@dd1730.kasserver.com> <6d448fd8-8fda-d795-accb-6b96cd128ccd@gmail.com> <652fdc5a-a164-2054-ed61-305a2b72330a@gmail.com> <20160603142421.346B81A81725@dd1730.kasserver.com> <9814df22-9854-616b-bf02-d0742efefaff@gmail.com> <20160603145857.8413F1A8323C@dd1730.kasserver.com> <1fb072b3-9b9e-1dfd-6b39-7875587b6c7d@seld.be> <5751B50F.2090003@garfieldtech.com> To: Larry Garfield X-Mailer: Apple Mail (2.2070.6) X-OriginalArrivalTime: 03 Jun 2016 21:31:45.0622 (UTC) FILETIME=[54111F60:01D1BDDF] Subject: Re: [PHP-DEV] [RFC] [PRE-VOTE] Union types From: bobwei9@hotmail.com (Bob Weinand) --Apple-Mail=_2B879295-0513-465E-8F51-A35B5522569B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="windows-1252" > Am 3.6.2016 um 18:49 schrieb Larry Garfield : >=20 > On 06/03/2016 10:16 AM, Jordi Boggiano wrote: >> On 03/06/2016 15:58, Thomas Bley wrote: >>> To me type declarations help to make my code easier and more = consistent. >>> Having multiple scalar types for a single function parameter is = against this goal since I need extra logic to handle this. >>>=20 >>> e.g. function foo(string | int | bool $bar) {} makes no sense in = weak mode since string can already handle int, bool, float, etc. >>>=20 >>> having different behavior between >>> foo("42"); function foo(string $b) {echo gettype($b);} // string >>> and >>> foo("42"); function foo(string | int $b) {echo gettype($b);} // = integer >>> also makes no sense to me. >>>=20 >>> Things like string|array are useful (e.g. str_replace) since we can = cast the string easily to array and calling a string parameter with an = array would give a fatal error. >>=20 >> That is a useful case, and don't forget also return values, e.g. all = the XX|false-kind of return types it's also nice to have. >>=20 >> I don't think for function arguments it's massively useful and I = doubt it'll get put everywhere, but it's nice to be able to express this = when you have to. >>=20 >> Cheers >=20 > For parameters, I really don't think | is going to be the common use = case. (It should still be rational, but I don't expect to see it day to = day.) InterfaceA & InterfaceB Is the more useful use case for = parameters. | is, as noted, likely more useful on returns. (even though = I would discourage their use in most cases for reasons I won't go into = here). >=20 > --Larry Garfield It won=92t and it should not be *common*. But there are legit uses = cases: = https://github.com/amphp/aerys/blob/2a4d626fb1b8b8ac9d91711085c04eaabdec77= 68/lib/Host.php#L87 = This concrete example shows that a class may implement multiple concrete = interfaces which all get the same/similar behavior locally. [And = somewhere else the code checks for each element in the array what = classes it implements and marks them appropriately.] Sure, you could have ->addMiddleware($foo)->addRequest($foo) =85 or just = a single ->add($foo). It=92s maybe not the most pure API, but the most = practical one. But I agree, I myself would discourage usage of union types in most = cases too; but there *are* legitimate cases which shall be also properly = typable. Thus we need it. Bob= --Apple-Mail=_2B879295-0513-465E-8F51-A35B5522569B--