Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112199 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69485 invoked from network); 7 Nov 2020 21:25:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Nov 2020 21:25:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1A3C61804D8 for ; Sat, 7 Nov 2020 12:47:21 -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.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 ; Sat, 7 Nov 2020 12:47:20 -0800 (PST) Received: by mail-lf1-f54.google.com with SMTP id e27so6807961lfn.7 for ; Sat, 07 Nov 2020 12:47:20 -0800 (PST) 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=OILZROrCjxUDREVUh+imhAtilnLrhde0TkjfIRAV+IM=; b=KbKBQ8QQdUV5YC89Z50DwSU5VDMgJUNdPwaIWhPC1LyiYeuMGG4qMe3nVYVSAs08kV CYA8xEXNB9D9EntDhXOcfN1i+DQkpLKTDAmp8qSZ6uCApDgmVqZv1chrIrutxHe+yE5w tup2MbA3ylr59jDcDbceo+hzAcpJVMu2+MBE3Ofl3G7N2zqGC0CN9+kSSby9VIW7Fnnt imNTONSJSJl2G8vxGbFaeslAryeIK5Yufvv5Xhw+RPx9h7UxTS6eHmBZR00zLp/CmBR9 HcZXBZ0vLfqWUcgASnWYXwL4u1cUgZcPzdkU/xMn9oHE1kUOHY0xagZj7xuYguUyctnb tMuA== X-Gm-Message-State: AOAM532JjrU5HLR+EZBSO8XdhWqJl5J2eGzrZtHNnJWW/nwxeGiAZTtZ Xm91rh6EYazbqvx7t4vRhI4fsfiLBMa/iVj+fGbZjA== X-Google-Smtp-Source: ABdhPJyCS/eUOtZu9vMr/qfVkxjAuqZrdz/qJObk17iJBB8ybbLpOIG6gmkIP5T8wJLnZuGfxWx9fnuOaNl4MrOAt5Y= X-Received: by 2002:a05:6512:2098:: with SMTP id t24mr3274901lfr.116.1604782039217; Sat, 07 Nov 2020 12:47:19 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 7 Nov 2020 14:47:08 -0600 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: Eugene Sidelnyk , PHP Internals Content-Type: multipart/alternative; boundary="00000000000063d23305b38a6faf" Subject: Re: [PHP-DEV] Union `&` operator From: pollita@php.net (Sara Golemon) --00000000000063d23305b38a6faf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 types are... **checks notes**... oh, wow. Actually still pretty new (introduced 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 --00000000000063d23305b38a6faf--