Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115601 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56701 invoked from network); 28 Jul 2021 07:02:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Jul 2021 07:02:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BE4C81804B0 for ; Wed, 28 Jul 2021 00:29:32 -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=-0.7 required=5.0 tests=BAYES_05,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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 ; Wed, 28 Jul 2021 00:29:32 -0700 (PDT) Received: by mail-ej1-f48.google.com with SMTP id hp25so2968008ejc.11 for ; Wed, 28 Jul 2021 00:29:32 -0700 (PDT) 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; bh=7t4Vrn/lhcPRWeteYl6gBVwbuxyvZ2uDRLJjohPonKw=; b=awXWKEKw3Vkp9ySZl4KgzO/gr/2La5PVpJGxtj+20Gdcb3hr5+P4W1/T15PkykVKV1 YQhDWSYs1HY6WQeT2ry22PO8x6EcMnumoek5lurdBD9JubYR0RgCHVvSuhjfG3MGP3By cNP0YJeEb3vuKghMW58t69ATT/Sd0nOFpBXUCzybqjBwxN207hKiaG0dmNZATrUkk0bW kbqLCU/bGUd7zjBxP2aXWQEJ6mNggzud9TcCp7HPcDXrMr9V6vIKqhbA6qvDVU8UPZnE Um3MUWKVaWieRgRXVKUPdD9sEAzMYMfcPnHUr/QfzLZNiskd8iDC2UkG0/1EV86PxT6c HKhg== 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; bh=7t4Vrn/lhcPRWeteYl6gBVwbuxyvZ2uDRLJjohPonKw=; b=OPyFHd040P8wD0VRRzSmkmkxMPdecCrbWhzpqmq2suoxnNCdkbNzHw1uubXc/X7zw2 HZoSMgPbQfbT3rW2BXGjfJ1xJ2p2pM4VZHgQjBscqXYme3z9F9UdcCPErHAx2sIxN4a1 Sf8C1IkKU0m/cot32AZCPjz6pb1Ztx821lG4sjNOnOYk9BQYHFYNgE+zeNKvUI1Xhq9x YaIl4seOSjQT7QA8/8Kv9H5HFflktkVrRo/YGsnbvw3vAJLWKVUzg7V0soynE5jeyl5D xzKR3DBnt58HUb5OkWfotl0ZY61qdtxM0hXodQ4Qnk3VV9pQQLAvCIJnvy9GIVNUwHWv pBjw== X-Gm-Message-State: AOAM530dU0EnxCh5DxV/4ywbKZIY6TDhSevpXgl2IkmaNMDFnipYwkme kTBTTcM/tfAZ+gjMKRMTOK4ZP0GjyH9tBT1qt/88lx/M X-Google-Smtp-Source: ABdhPJxiTJBpCXCX38YjEMSq1JF/Q06jZ3MfYSvFNvDQYq4+oEaMOvChegFVRbLmN0iCktDaXtW/Lmw2KmOVORlW0QU= X-Received: by 2002:a17:906:e21a:: with SMTP id gf26mr11306303ejb.313.1627457370775; Wed, 28 Jul 2021 00:29:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 28 Jul 2021 10:29:18 +0300 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="00000000000078e3b105c829f25b" Subject: Re: [RFC] Nullable intersection types From: nicolas.grekas@gmail.com (Nicolas Grekas) --00000000000078e3b105c829f25b Content-Type: text/plain; charset="UTF-8" as proposed by Nikita and Joe, I'm submitting this late RFC for your > consideration for inclusion in PHP 8.1. Intersection types as currently > accepted are not nullable. This RFC proposes to make them so. > > I wrote everything down about the reasons why here: > https://wiki.php.net/rfc/nullable_intersection_types > > Please have a look and let me know what you think. > Hi everyone, Thank you for the contributions made to the discussion so far. I'm mostly AFK these days, hiking in Greece. That gives me time to think about comments made here, among other things :) Given the strong opposition from some, I considered withdrawing the RFC. But since I also see some nice support, I decided not to: even if the proposal is rejected, everyone should have the right to express their opinion, and the vote is the only option to not let only the most vocal or the most eloquent decide for the others. For the same reason, I'm not going to restrict the voting options to (X&Y)|null as some requested. I will change my mind if we spot that some syntax would put us in a corner. But so far and while I tried to be as careful as possible, all syntax proposals are future-proof to me. I get that some have strong coding style preferences, but that doesn't make a technical argument. It's true that deciding to allow no brackets won't allow us to force them later on. By why would we *force* them in the first place? While you may not like relying on it, operator precedence is a nice thing. I would hate having to put brackets around every single expression in PHP. For types, there are only two to three operators: we don't have to remember the full precedence table. And only one precedence makes sense anyway, so it's easy to remember. I'm not advocating that we should forbid brackets. Actually I'm going to vote for allowing both with and without them, because I don't want to force my preferred coding style to others. I do have a preference for using the `?` operator. It is compact and nullability *is* a flag. I'm reviewing code that use foo|null|bar, other that use foo|bar|null. That makes reading the code harder. About its precedence, I explained why I didn't need to be creative in the RFC: `?` has to be the lowest precedence type-operator. Any other options would make no sense from a logical pov. It would be so sweet and consistent to be able to use it all the time to express the nullability flag. I would mind if we allowed both `?` and `|null` btw. Intersection types are a really useful addition to the language, please don't suggest I framed it otherwise. I just thought that they would be a lot less useful if they were not nullable, especially considering that they could be part of public signatures that have to be maintained with BC in mind. I'm happy that some agree with this and share their experience about it. Nullability is a special beast in PHP. We have a range of operators dedicated to it. That's also why I think it deserves special care, and why I think it's important to have this discussion before 8.1 is out. To me, the feature freeze is also useful for this: polishing features that are about to be released. I don't see us rushing here. Let's do a careful and rational analysis of the proposal and vote on the very asked question. We do have enough time. TL;DR: I'm carefully looking for blockers and I'm calling for more examples if you spotted one! Cheers, Nicolas > --00000000000078e3b105c829f25b--