Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93761 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57781 invoked from network); 4 Jun 2016 11:45:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2016 11:45:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.216 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.216 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.216] ([81.169.146.216:24881] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/13-25194-06FB2575 for ; Sat, 04 Jun 2016 07:45:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1465040733; l=7423; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:In-Reply-To:References: MIME-Version; bh=3eOFWwuZ2B9O+sR2FnXOkPONlrBWSTm1fdBF+f2+mDM=; b=uIXLx5L9c7uHHcndah1ExIP4ogHtQ1MzVt/WPuhlH0M9zY6Ryl0CDXSbq35EI2WhSDn hSpH//0VbJ/MQFjIZqRdz0EvrUMxK/pZb7nBWmHNeoGgAyf+4p6BqYKK6/Xg0xQK0bdhP frMNnW5LQsAc/zLeMImz9o4vUINhokzQX8Q= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3Y6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f45.google.com ([74.125.82.45]) by smtp.strato.de (RZmta 38.2 AUTH) with ESMTPSA id e02ebbs54BjX5ay (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Sat, 4 Jun 2016 13:45:33 +0200 (CEST) Received: by mail-wm0-f45.google.com with SMTP id m124so18619538wme.1 for ; Sat, 04 Jun 2016 04:45:33 -0700 (PDT) X-Gm-Message-State: ALyK8tI1GJi5uttyKdb0UGEs0VR2qozN3vcCR+BNIYeH3S2NJ0SprLpRq9NdY2h2B1e66M8WRkq37oPEY6/oEA== X-Received: by 10.28.9.139 with SMTP id 133mr3846490wmj.93.1465040733060; Sat, 04 Jun 2016 04:45:33 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: Date: Sat, 04 Jun 2016 11:45:23 +0000 X-Gmail-Original-Message-ID: Message-ID: To: Bob Weinand , Larry Garfield Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a11444ba279c949053472604a Subject: Re: [PHP-DEV] [RFC] [PRE-VOTE] Union types From: me@kelunik.com (Niklas Keller) --001a11444ba279c949053472604a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Bob Weinand schrieb am Fr., 3. Juni 2016 23:31: > > > Am 3.6.2016 um 18:49 schrieb 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);} // integ= er > >>> 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 y= ou > 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 > > > It won=E2=80=99t and it should not be *common*. But there are legit uses = cases: > > > https://github.com/amphp/aerys/blob/2a4d626fb1b8b8ac9d91711085c04eaabdec7= 768/lib/Host.php#L87 > < > https://github.com/amphp/aerys/blob/2a4d626fb1b8b8ac9d91711085c04eaabdec7= 768/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 somewher= e > 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) =E2=80=A6 or= just a > single ->add($foo). It=E2=80=99s maybe not the most pure API, but the mos= t > 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 typabl= e. > Thus we need it. > > Bob I don't see where the massively added complexity justifies the very few edge cases. That 1% can still be checked manually. For Aerys\Host it could also be solved with an interface that just doesn't have any methods. With the disadvantage of callable not being in the same signature anymore. --001a11444ba279c949053472604a--