Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115564 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5162 invoked from network); 23 Jul 2021 15:24:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jul 2021 15:24:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 76A2918050B for ; Fri, 23 Jul 2021 08:50:10 -0700 (PDT) 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.80.0.0/12 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12olkn2093.outbound.protection.outlook.com [40.92.21.93]) (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 ; Fri, 23 Jul 2021 08:50:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QUqqMRpaUX1QGsH75EXQ/khlyaqzgL2c5L7rmd1qUtJiSduP4/wBxY6k1v3ZbMY3PLr6eu18MmxHx4qL86sLb0yOEUKGL/q9E63piTuyTvE6eebxFvxC56RR/UO6bx6Mep1offkU/sYmrbCwtWYn0ZgXH+DYo39i+VFzB1QH71txeYBH7KGOgnbTY5cWtGvfVyPR6av0zQ/As+/mdF0VYlmPxbbqyOuTJ9yskp4fMV3ij1n3B1Jd6Z9NrtVq84kASBl+TOXxa81PPVHQ/fuRvs+nn8Zis0MCVBHSixuk8p9QUKM1GXzdBrcxIyH1f5meLpfva4YM0Cd9oXiHefMd3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S3fsSn9J/Q5UxahGWRr43AOGIWsH7cKTcbJY3d4vMFQ=; b=HE3ibsTxfd2y2qWnQnqVKa9jTU2Cal7bh/H+4TxzFaHZA+uzJoBh/ZJ7aOBmLgLYGZ7ceMUlN+pU3Gssm68EuJIxkv5qCtxT+58GmDyZbMHYQUO2y8EU+WgmOjqUUgqUfU7WXhdRUft94dvAGkNun28GBzX926mzz5LBspbF15QwELpXNAPRC7qCmVH7wb9bOAchBxLqGecUAU3quSHzVYMPeC3xasq1gWQ0nWSyY8zwE583FnHhwqapIup7skQw0GjB/+k1NRjr90tFOvdp48wi3+kNVa2zul0DTGzfPLSjSj2IpuZZhm+PFxndcex9uBve5Jv2t2e/LB5jEy5gtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S3fsSn9J/Q5UxahGWRr43AOGIWsH7cKTcbJY3d4vMFQ=; b=kMG1/0LMhEj8gWEvL83eWSb7UKB6Ezj/1jMHrtcRGbvqe2oESpN1CqUut0H+4bJ3wav0vNvgpigBzh/l4TdipUVERrhBgMtXv4wfCbtGTNsYM1z/aghtdPtt4Aku9x6nlSV49dXzyVJqMK8sb5jwLe9ySiYymioO4eNV2h5jYQp2oAfJwpvS9kW/ZOXgdfxXnwRAwV0DuYCXOOaxP1DPHKPfGaIDpkZlbjGSHFjvHF22kZpvufG4h/o4LfBBAuyUNdmSbbr8ZrfT/dXw/A7kAV/96MNAfXwNjq077FEEoMGAKgDfw3ZXAwDgdaVOvoGkhgXA1osyCsz8LIsMsqW2dw== Received: from BN7PR05MB4033.namprd05.prod.outlook.com (2603:10b6:406:90::33) by BN8PR05MB6036.namprd05.prod.outlook.com (2603:10b6:408:42::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.9; Fri, 23 Jul 2021 15:50:06 +0000 Received: from BN7PR05MB4033.namprd05.prod.outlook.com ([fe80::20e6:a36f:861b:5c81]) by BN7PR05MB4033.namprd05.prod.outlook.com ([fe80::20e6:a36f:861b:5c81%5]) with mapi id 15.20.4373.009; Fri, 23 Jul 2021 15:50:06 +0000 To: Nicolas Grekas , PHP Internals List Thread-Topic: [PHP-DEV] [RFC] Nullable intersection types Thread-Index: AQHXf6lG17ahYHI3HkyKQ206do+j+6tQs7S/ Date: Fri, 23 Jul 2021 15:50:06 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [kNZw7Mo4V+xQq72geg6WUvsPUBtuKxNg] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: cc78c5df-d3ff-4a44-534e-08d94df18ace x-ms-traffictypediagnostic: BN8PR05MB6036: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vrHUuvdY3r5thHyteZ63rUvKJPBnOzSCt3yUlgreKYv5ScletMp4O4DmIZvyENpL+d7uddI3Lwq/clMrPdedafWft1CWvt9BqKXJgrw85uDkDR9LeHWX/0F6lA78ETaQz0+c6qbSWHKE77yf4gwWRyMPdOD9AyB1wZ8iy+k4eFx9rOPaBS37UdqlIACSnaCdUedzRz9gS27q53qk+iOkjBR1cqoMv7jJos5Qw3Wd/9kLD9/4mSBDr9fsoUlhZUb5fOCm5gstchnYi42N8x/pm3f1cFr9dDVM//D5haMtQTCoRc//QMJn8UO9/UcR7L4Q7nZB6tSl6HGwM3azoLwkrtYHbFDX9JYGMjcWXlFGI6SQrxoN1Cqqsm2zW9hntuuOQ6IhWiQn5DdzVgtyoyJeyLZ0i33s7pAqtlz79JQXlgtkPIUZOzBvk/1rl1KFSH9OZKbPWZayqrCWI3IwIYYaR/fq+Z/MwQrUvVOTFyd3MeY= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: c2LIa4lqOTY1P2oYwuKWUB+8/Bo1oEZ73TiK/LSV/Rpv9fY0F1cPDR1MxAYAzrTeVe3g1idcDgkvFieY7kgdywHLr8VqHSn8gm5lY4FtVQVyKh6vNTdrggfcWl2nEhX9WtcptRxRXkecP/t8oPgVeg== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN7PR05MB4033.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: cc78c5df-d3ff-4a44-534e-08d94df18ace X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jul 2021 15:50:06.0220 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR05MB6036 Subject: Re: [PHP-DEV] [RFC] Nullable intersection types From: theodorejb@outlook.com (Theodore Brown) On Friday, July 23, 2021 at 4:58 AM Nicolas Grekas wrote:=0A= =0A= > Hi everyone,=0A= >=0A= > as proposed by Nikita and Joe, I'm submitting this late RFC for your=0A= > consideration for inclusion in PHP 8.1. Intersection types as currently= =0A= > accepted are not nullable. This RFC proposes to make them so.=0A= >=0A= > I wrote everything down about the reasons why here:=0A= > https://wiki.php.net/rfc/nullable_intersection_types=0A= >=0A= > Please have a look and let me know what you think.=0A= =0A= =0A= Hi Nicolas,=0A= =0A= Thanks for your work on this. The RFC states:=0A= =0A= > the preference of the author of this RFC is to define =93?=94 as having= =0A= > a lower precedence than any other type-operator, and thus to use=0A= > the =93?X&Y=94 syntax.=0A= =0A= I also strongly believe this would be a mistake. When union types=0A= were introduced, it was explicitly decided not to use the `?(T1|T2)`=0A= syntax, for the following reason [1]:=0A= =0A= > this notation is both rather awkward syntactically, and differs from=0A= > the well-established `T1|T2|null` syntax used by phpdoc comments. The=0A= > discussion feedback was overwhelmingly in favor of supporting the=0A= > `T1|T2|null` notation.=0A= =0A= `?T` is a shorthand alias for `T|null`, and the alias cannot be used=0A= to add `null` to a union type.=0A= =0A= Although PHP doesn't yet support generalized union and intersection=0A= type combinations, this is almost certainly something we'll want to=0A= enable in the future (in fact, this very RFC is a step towards this).=0A= =0A= But if union types don't support the shorthand nullability syntax,=0A= and intersection types require it, how will the syntaxes be combined=0A= in the future? E.g. will we write `null | A & B | C` or will it be=0A= required to use something like `?A & B | C`?=0A= =0A= The latter is not only syntactically awkward but also very confusing.=0A= =0A= Since `|null` is the only supported syntax to add `null` to a union=0A= type, for consistency the same syntax should be used to add `null` to=0A= an intersection type. This will avoid confusion and inconsistency=0A= down the road if a future RFC enables more general union and=0A= intersection type combinations. It also avoids the need to define a=0A= precedence for the `?` type operator.=0A= =0A= As you note in the RFC, PHP already defines `|` as having a lower =0A= precedence than `&`, so `X & Y | null` can only be interpreted as=0A= `(X & Y) | null`. This is consistent with other languages such as=0A= TypeScript, where `A & B | C & D` is parsed as `(A & B) | (C & D)`.=0A= [2]=0A= =0A= Since precedence is already defined for this syntax consistently with=0A= other languages, I don't think it's necessary to require parentheses=0A= if we use the `A & B | null` syntax.=0A= =0A= Best regards, =0A= Theodore=0A= =0A= =0A= [1]: https://wiki.php.net/rfc/union_types_v2#nullable_union_types=0A= [2]: https://github.com/Microsoft/TypeScript/pull/3622=0A=