Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116236 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95591 invoked from network); 6 Oct 2021 15:24:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Oct 2021 15:24:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E28EB18054A for ; Wed, 6 Oct 2021 09:09:18 -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,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-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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, 6 Oct 2021 09:09:18 -0700 (PDT) Received: by mail-yb1-f173.google.com with SMTP id q189so6661896ybq.1 for ; Wed, 06 Oct 2021 09:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=ryM4O0s+/tVfmq1L1Ug+QPtOUTGu6+jv/WfUaU9Crl0=; b=nThVI1zytQUuZCn838uRPgpZ/F4kMl1UNpTiBaMhsX8myxBQPFvhFNNpze4hiYFS6i O988zphwbctin+diYVlG6iFlKRuC0fsC0lxEL6xU7aL4j6h4omm9LrXsrMMWVcT3Er8a bZQEmECBR7H0X80P2SSc3jTKtf9TUGYfQk6uO0EYj44I7E5/oBonDO/nY3rIeyfYJY10 rQ0lLIv8sOqSEiC4whd20VjvgyJJE73MgfQdDk5aMH2muAqh848a7vhkGlDDiZaa+gmz FCwe04L2tE4xlnes1cWaij9aS4bLSjtLvxR1LJZpTb6WYIoBEK35pfupJs/ZrlmfUKxE b1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=ryM4O0s+/tVfmq1L1Ug+QPtOUTGu6+jv/WfUaU9Crl0=; b=j4aBCI16UthhDkmLcITpicBEc1YFZOzNT2FBD3R9NZGr+i53yu1kBPcmXAtNj6A91a hEJafIEvkbQKgpzX+AWgagtBsrkFcofCiJkBFTnnTZ1P7NzL03kRnVU+TrOBeQShsca5 vggAQqjhrFGbRz+SwESQROFFT8N74pNA1Mc7jISxMCD1ptrtA4GFPVqrFIX7hZh34h52 Tl1EB0+NKUQY+xtsTtFBt3jOZm5v/W4Z2a0LQIY43FXKgwpCEu/TSNMae5SumBANH/Bs CO8FquwdIzDBH5OauNQIkwHrXvYtQCZ5YtrBrwwP9OyRYFYwNX1+y3ZwNE7pnspNx02V 9rNg== X-Gm-Message-State: AOAM533RPEL96d6w6bhL8JXFNDH6MfG1suWLQZRouCcU8cwKdST3yakP 6gJmS20ywX2rEetF26pprxG2/NBRG+bZRSh3xn2sLPW2fshY3A== X-Google-Smtp-Source: ABdhPJxvfxjbzBFXpnIrZZ7fALwY+wIxTDbEPfmPxbk2oLUEBlx2LBIq8gR0gZt+8hOu9c27gG58LTfBQZ5BiRd9X+w= X-Received: by 2002:a25:ae92:: with SMTP id b18mr23221744ybj.220.1633536552055; Wed, 06 Oct 2021 09:09:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 6 Oct 2021 17:09:00 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000e9b66305cdb15dc6" Subject: Re: [PHP-DEV] [RFC] Allow null as standalone type From: george.banyard@gmail.com ("G. P. B.") --000000000000e9b66305cdb15dc6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 4 Oct 2021 at 04:33, Levi Morrison wrote: > I don't see the word `void` in the RFC. I think there ought to be > something said about how naked `null` is different or not different > than `void`. Added a section which attempts to explain the difference between both. On Mon, 4 Oct 2021 at 09:09, Nikita Popov wrote: > If we make this change, I would however suggest to also support "false" a= s > a standalone type. I think this change primarily has benefits from a > typesystem completeness perspective rather than a strong practical need. > From that angle, it would be nice if all types that are usable in a union > are also usable as standalone types, rather than shifting the special cas= e > from null to false. > I'm not against adding false as a standalone type, but I haven't amended the RFC just yet as it would require some major rewording and I want to be sure most people are on board with this change. On Tue, 5 Oct 2021 at 17:55, Mike Schinkel wrote: > Regarding the RFC's proposed disallowing of `?null`, is that really neede= d? > Yes, this is in line with PHP's current type redundancy checks. One cannot write ?mixed, nor int|int, nor iterable|Traversable, as the types are redundant. On Tue, 5 Oct 2021 at 23:58, Alexandru P=C4=83tr=C4=83nescu wrote: > But there is one more small elephant in the RFC that I believe should be > discussed. > null|false type will not be a nullable named type but it will be an union > between two named types. > > It's not totally unexpected. All types that are combined with false are a > union type so far. > > But also, related to null, it will be the first case that will be > different. > So far, all types that are combined with null are not necessarily union > but their other type that has an allowsNull() that returns true. > > One could argue that we can also have it as a ReflectionNamedType with > getName() =3D 'false' and allowsNull() =3D true. > > I feel that the preferred solution will push more towards the general > desire to represent the nullable types notations more and more like an > union. > I can see how what was initially proposed in > https://wiki.php.net/rfc/nullable_intersection_types for (X&Y)|null > might end up being UnionType(IntersectionType(NamedType(X), NamedType(Y))= , > NamedType(null)) > instead of the originally proposed IntersectionType(NamedType(X), > NamedType(Y) with allowsNull() =3D true. > > I mean, that's not necessarily a bad thing in my opinion. But maybe it's > good to discuss the future plans as well. > For any new nullable construct should we use a ReflectionUnionType with > ReflectionNamedType for null and not use the allowsNull method? > Should we have a plan to convert current nullable constructs to a > ReflectionUnionType and eventually drop the allowsNull method in PHP 9.0? > From my understanding and the comments in the source code, and Nikita might want to clarify, the only reason why it still returns a NamedType is for BC, to allow tools that worked on PHP 7 to still run on PHP 8 even if nothing else changed. As Reflection based tooling gets updated to deal with the additions to the type system I expect that we will change the representation of ?T to a ReflectionUnionType, as to maintain the old behaviour we do things that could be removed and simplified by using the more standard representation. On the other hand, while we have the allowsNull method maybe we can keep > the pattern and not have a BC break and use it everywhere. > With an union, you need to iterate over all elements in the union and > check that one is a named reflection for null. > Is there something we cannot achieve if we do it like this? > This is incorrect: https://3v4l.org/P9U4u There is no intention to change this behaviour in this RFC. The slightly amended RFC can be again found here: https://wiki.php.net/rfc/null-standalone-type Best regards, George P. Banyard --000000000000e9b66305cdb15dc6--