Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112202 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90597 invoked from network); 8 Nov 2020 02:44:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Nov 2020 02:44:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 284141804C6 for ; Sat, 7 Nov 2020 18:06:29 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 7 Nov 2020 18:06:28 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 2DBDB9BA for ; Sat, 7 Nov 2020 21:06:27 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Sat, 07 Nov 2020 21:06:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; 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-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=hT1hhTD/3nDN1NuzE48hgoAOClQjE+mNBwKIMHOio ME=; b=XWNCxomF5P+JTwkKsl8J+2J0fkne9sGBKZm35d3GcGwcZjwk2fdTSPp1F kLwdmbjBjs0ufyA6VTRmF3kKGVXm+2nWAXNgGPYbNA89Uxwdbzu9VzY3ClbijOb/ LNL4AEhMiNaByNuUURCSjZWgsl65m4cF+u2mfmLHscrBLDltbVmrL6moCI2ix/71 WTvFIr71V00IPD3xFT3VyHJpbsFxcTqjWKN5Ej9365e2d54F++OIdGZ4zhI+gYhg l09aWeXZqwjyTHR4Hb4wEhVbXW9OyWcTz/TNko8PPayc9tn1PSwLks7Y7QX8UMqZ 00Ywl6hh+oyZbA3kiIr3/oyS2vgAA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudduvddggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5CC2314200A2; Sat, 7 Nov 2020 21:06:26 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-570-gba0a262-fm-20201106.001-gba0a2623 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Sat, 07 Nov 2020 20:06:05 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Union `&` operator From: larry@garfieldtech.com ("Larry Garfield") On Sat, Nov 7, 2020, at 2:47 PM, Sara Golemon wrote: > On Sat, Nov 7, 2020 at 9:33 AM Olle H=C3=A4rstedt wrote: >=20 > > 2020-11-07 15:12 GMT, Eugene Sidelnyk : > > > function foo(A & B & E $object) { > > > // some work > > > var_dump($object); > > > } > > > > > > > You mean intersections? Psalm supports this notation. > > > > > IIRC we discussed intersection data types when union types were on the= > table and we settled on a "take it slow" position. That said, union t= ypes > are... **checks notes**... oh, wow. Actually still pretty new (introd= uced > in 8.0). >=20 > My conservative side wants to wait and see what the community does wit= h > unions, but if static analyzers are already providing this functionali= ty, > then maybe the community has already made its position known. I would be very in favor of intersection types. It's not really useful = for primitives, but with interfaces it becomes quite handy. > Questions to answer in any RFC on this topic: > 1. Do we support complex types combining unions with intersections? > e.g. function foo(((countable&traversable) | (stringable|jsonserializa= ble)) > $obj) { ... } > Pros: Super descriptive > Cons: Super ugly > My opinion: Maybe, but not immediately. Let simple unions/intersectio= ns > bake for a version or two. I'd favor a type being exclusively unions or intersections. No mixing, = with the possible exception of allowing the type to be nullable. So Foo= & Bar is OK, Bar | Baz is OK, but Foo & Bar | Baz is just more complex = than any reasonable person should be doing. > 2. Do we also bring in type alliasing? > e.g. > type CountableTraversable =3D Countable & Traversable; > type AllTheSerializations =3D Stringable & JSONSerializable; > function foo(CountableTraversable | AllTheSerializations $obj) { ... }= > Pros: Can make a given code base more readable once you know the types= > Cons: Can make figuring out types in a new codebase harder. > My opinion: Yes. Sooner the better. This is a separate RFC from intersection types and should be submitted s= eparately. That said, yes please! > 3. How does this intersect (pun!) with coersion when strict_types=3D0 = ? > Initial thoughts: Probably very poorly. I'm unclear how/why it would? Please explain? > 4. Should we be considering other bloat^W features? > a. Exclusive Union: type SingleSerialization =3D Stringable ^ > JSONSerializable; // XOR: Must be one, but not both > b. Blacklist: type AnythingButDOM =3D !DOMElement; > My opinion: Hell no. Just spitballin'. >=20 > -Sara Hard pass. At that point, make separate methods. --Larry Garfield