Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116234 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43777 invoked from network); 5 Oct 2021 22:14:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Oct 2021 22:14:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7EF6918054C for ; Tue, 5 Oct 2021 15:58: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.2 required=5.0 tests=BAYES_20,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-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 ; Tue, 5 Oct 2021 15:58:31 -0700 (PDT) Received: by mail-ed1-f53.google.com with SMTP id z20so2383194edc.13 for ; Tue, 05 Oct 2021 15:58:31 -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 :cc; bh=f+LLvK8s9s4XmF/AeB9a93+YSn1twg++MH7Fjlq3YW0=; b=RGjPrOzpegJP5kVy+zXctxXMknQnbEdnXkYKKtRrvwGoAiy1ZlP1uwERpNhv646dA5 iHV+baR57HDfU5bd659HKAmFyghtuPOD0LdBkq2EkswyFG9I+hXxpC4WH6eDNcrENcdk a8BkDklUaN2YcnzGjUv3wVA77ZXDGIhg4n/OijdyIbed2TN621TIFHltl2LYrsucsRXu WFKp7Vmo0xmW62lOfuk03T304GDsM10TkRk+Z0qwUk243JuDY7xv3z5jVLF3bcTpTaC/ zYRjmeXialKxX/+Or5DEBPOIO9bEUJGmYpkbUMDnUv7cbvuHVcq7/Ci7uLTOWG/JmaLz IN7A== 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:cc; bh=f+LLvK8s9s4XmF/AeB9a93+YSn1twg++MH7Fjlq3YW0=; b=WFG6fNykbhpzELzNz65cqEurHgod4sHL6N8txVvivfCf8IQ0YAUeNgp8zK9U2A9uJS TUrVGMebFrF/sJEDyeHVyDGsBEBkWavUgnDCOk598+A4BH9eyf6LpjwLX5rNaiLJwEWS pbc4NE7UxS1vTGj82bcckp+yG67lti/GRjJAHado/odFjF32386+9wP4Vk3Irx70Ygb9 ZFaFxBRCc4wBsuquUzMBWTzVHjjx6FnbGzP8KH4RFyFmgzbHTYZX0kT9TITge8z89I+w eK81taxRvh/e4ToSx4D5zT7/FqzM0OzK8T7Ahq33njG+4Vkq4viXuGd8b+g//C8gF86/ yXTw== X-Gm-Message-State: AOAM530cXUFs4yfCJ9AtXu1eEKOqklHNHgFAmTz2cGMXJVEp4NzP0A5S 74njXhoyYhQsFswmCYJC32GdvFSIJAe6iAzXELOHe3k/+omPOg== X-Google-Smtp-Source: ABdhPJwi1eXE5Njn3P3QwYqBPgrp87S8NM95F40ehRgNYByk/SLfdvgb43EbXxi8RWEAMC0c0q6IjL2nMBzdKpgMyzE= X-Received: by 2002:a05:6402:26d1:: with SMTP id x17mr25286914edd.300.1633474710685; Tue, 05 Oct 2021 15:58:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 6 Oct 2021 01:58:14 +0300 Message-ID: To: "G. P. B." Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000e15b6505cda2f7bc" Subject: Re: [PHP-DEV] [RFC] Allow null as standalone type From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000e15b6505cda2f7bc Content-Type: text/plain; charset="UTF-8" On Sat, Oct 2, 2021 at 6:07 PM G. P. B. wrote: > Hello internals, > > I'm proposing a new RFC to make 'null' usable as a standalone type. > > RFC: https://wiki.php.net/rfc/null-standalone-type > GitHub PR: https://github.com/php/php-src/pull/7546 > > Best regards, > > George P. Banyard > Hey George, thank you for driving the effort forward. This looks good to me and I think having null as a return type makes it a bit more clear. I think the difference between a function returning void vs null will be clear enough. 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() = 'false' and allowsNull() = 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() = 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? 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? I don't have a strong preference for either. But I think it would be good to discuss it. While writing this, I realize that the RFC should probably specify in the Reflection section also the simple use case, null, not just the null|false combination. I assumed it would be a ReflectionNamedType for null but I think that it should be clearly specified along with what the getName method will return. Also, what will the allowsNull method return? If false, should the recommended pattern for checking if null is allowed be ($reflectionType->allowsNull() || $reflectionType->getName() === 'null') Or maybe the name should be 'NULL', to match the result of gettype(null)? If not, maybe we can mention the difference to the gettype function. Regards, Alex --000000000000e15b6505cda2f7bc--