Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112207 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51311 invoked from network); 8 Nov 2020 17:08:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Nov 2020 17:08:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8B8941804B5 for ; Sun, 8 Nov 2020 08:30:19 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 8 Nov 2020 08:30:19 -0800 (PST) Received: by mail-lj1-f182.google.com with SMTP id y16so993870ljh.0 for ; Sun, 08 Nov 2020 08:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Gw5TPIhtMOdOpr+bSDDgglZCy8cHFm8BVFTqB4uTujM=; b=nSZqx50OmTVuQ0lsAbsFS2MGurakIuxmBax9CyP7I++4YFeuVpduGwQtWfQ5/VB82H fdukQVcvCl+X+twq2QF6rGGUPpmLkuY5PnnpXZR+pgm4mTxGyqUJ8xIxs5F3peD94PAn dbjrBXtPVL8/Ai8HuioDCpVskk92PPNy97gx7+QHuFLukpfCXWtGwICtTU0dcMZlp8hE W1ltpOpl+/F2k0Tuawy2DKft54Gh4vufTAkYn3f7dDv0PHv2BxYJKMp0ACrtBHmwDatD q3PhfAY0RzSLOil3aZTYPzZH76WJo2IBKzzKUuSy/lDTWRA678orIA9DDxKQXCgoK0pw H5KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Gw5TPIhtMOdOpr+bSDDgglZCy8cHFm8BVFTqB4uTujM=; b=trI2218/QvrLj9TIwYwcIEpavYm/uei8EQmLurOrNvu88cYjOwvQGv3/PH2BZbs7AW R8xX7FfwAUZTPN0cw/bF2aHDOCpqlH4tYiufwJEhFkulRyehZWTRYq1lWNkH6lrQ9iXg T35317EfAQ+Nr/JWpsNJWjpAM0UG6y4J75ASRFuQVKWTktrNGOiXdGY0VrgAV0n7hF7O QjcC3xY/9L6tAYjm2XZ1+ziId7i19d/+/SOyxKD0iqsGkFhOBiit5AwUuKtRbIVYTHAT 9qaglJZFqcux6s1Hb513Agc/A5TWyzq2q8oOsW68Y7Ar2qfx7hoZ4FVeVndHANr6e/zz HkSg== X-Gm-Message-State: AOAM532mXVhAOM3cAMv/gaCmrWoQ1W8Z0nWDFUtRcyF34e7rtU+PYill 8sdLDnIdJtuwvAmHN8iOzKuzz+Vbo/nHcq2j1yI= X-Google-Smtp-Source: ABdhPJyySkdEs+7bvJCsJiN48BMoEysDK7gL0NSX51qdFpfSivQqv2icnhE2/rC9GvHLp5rqti1t34I4PNqc+axWL2o= X-Received: by 2002:a05:651c:502:: with SMTP id o2mr4263149ljp.318.1604853015609; Sun, 08 Nov 2020 08:30:15 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 8 Nov 2020 18:30:04 +0200 Message-ID: To: Sara Golemon Cc: =?UTF-8?Q?Olle_H=C3=A4rstedt?= , PHP Internals Content-Type: multipart/alternative; boundary="000000000000e9854a05b39af50f" Subject: Re: [PHP-DEV] Union `&` operator From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000e9854a05b39af50f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > 1. Do we support complex types combining unions with intersections? We can do it at any time, so we should not hurry with this. If we think about why people would like to do such complex types - probably it is because PHP currently doesn't support methods overloading. Thus we'd rather introduce methods overloading than complex union structures, but with yet that is a different topic. > 2. Do we also bring in type aliasing? Think that would be great (class can define some types, which it uses, so that client code can type-hint it): ```php class Foo { public type Collection =3D Countable & Traversable; public function doThisAndThat(self::Collection $collection) { // ... } } class Bar { public function delegateToFoo(Foo::Collection $collection) { $this->foo->doThisAndThat($collection); } } ``` But, as Larry told, it should be a different RFC. > 3. How does this intersect (pun!) with coercion when strict_types=3D0 ? If we don't introduce complex structures (I hope), it should work the same way independently of whether strict_types is 0 or 1. > 4. Should we be considering other bloat^W features? Not really. There should be some case where such features are actually needed. Regards, Eugene On Sat, Nov 7, 2020 at 10:47 PM Sara Golemon wrote: > On Sat, Nov 7, 2020 at 9:33 AM Olle H=C3=A4rstedt > wrote: > >> 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 type= s > are... **checks notes**... oh, wow. Actually still pretty new (introduce= d > in 8.0). > > My conservative side wants to wait and see what the community does with > unions, but if static analyzers are already providing this functionality, > then maybe the community has already made its position known. > > 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|jsonserializable)) $obj) { ... } > Pros: Super descriptive > Cons: Super ugly > My opinion: Maybe, but not immediately. Let simple unions/intersections > bake for a version or two. > > 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. > > 3. How does this intersect (pun!) with coersion when strict_types=3D0 ? > Initial thoughts: Probably very poorly. > > 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'. > > -Sara > > --000000000000e9854a05b39af50f--