Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93755 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9664 invoked from network); 3 Jun 2016 16:49:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2016 16:49:23 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.26 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.26 out2-smtp.messagingengine.com Received: from [66.111.4.26] ([66.111.4.26:35763] helo=out2-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/C3-22497-215B1575 for ; Fri, 03 Jun 2016 12:49:23 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DEA8220860 for ; Fri, 3 Jun 2016 12:49:19 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Fri, 03 Jun 2016 12:49:19 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=P0LSwFK8hU9qfah qILh1Caot2bc=; b=D3hhjsU4M0SqWA35WWDLms5FIAjY1jwuYz1Svj1pNQD+NQB Q9Tmz3TkV6c5/9vh7p5+xxYPmRp+Yxmo5ojDSrLubawdBDJyeClDVFqeEXh/0Koz Tl82ZJT/MwTXgy2r9oI7XQ/bVj92lZyl5g9dHSD2gEfHqPNGHkVwnteYAI5I= X-Sasl-enc: ZE1kdxEuT3zvgvNlSMOtFZu0q+bwACxBhpqc5R/iRfbw 1464972559 Received: from [192.168.42.5] (c-50-178-40-84.hsd1.il.comcast.net [50.178.40.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 900AAF2A0A for ; Fri, 3 Jun 2016 12:49:19 -0400 (EDT) To: 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> Message-ID: <5751B50F.2090003@garfieldtech.com> Date: Fri, 3 Jun 2016 11:49:19 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <1fb072b3-9b9e-1dfd-6b39-7875587b6c7d@seld.be> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] [PRE-VOTE] Union types From: larry@garfieldtech.com (Larry Garfield) 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. >> >> e.g. function foo(string | int | bool $bar) {} makes no sense in weak >> mode since string can already handle int, bool, float, etc. >> >> 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. >> >> 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. > > 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. > > 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. > > Cheers 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). --Larry Garfield