Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115479 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73975 invoked from network); 19 Jul 2021 08:16:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jul 2021 08:16:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1A9851804DA for ; Mon, 19 Jul 2021 01:41:37 -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-Virus: No X-Envelope-From: Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 ; Mon, 19 Jul 2021 01:41:36 -0700 (PDT) Received: by mail-ed1-f45.google.com with SMTP id ec55so22910888edb.1 for ; Mon, 19 Jul 2021 01:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=VOTKs34OUxPOQ4PQ4ipdWUWw+ETbHVUhK151yQP0upI=; b=r5zBpam0jEgtGYZb6im6RMs4W4DBQqqOnSKdXinV1dHuCwewcRuN9KyGu1edkcBC+9 pvHaC08EpyFulX8S8VtAPTieO15GvRrjzXghIQ1OLXDiojs+hX+RTQ+6si/MTSUI2xju MRWaCDeHod88WnABrgpYjNtLUqgTRbjTLYKNP1+lvYN23+yxqAwgOUDqJoL3QOq4zb/8 C/5bUHhz3Br3Fr0CoyPBDqz3DmOckTVTlH/lH7FuhhpmHVldhpQbAK70OzgrXjnB7V+V 7JoP4+38DHTb8HysSLVytjSHKQGdfNgTqyU+suiO9AlRY4LW91gV6C/u/LB6W5Znc6eK BlCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=VOTKs34OUxPOQ4PQ4ipdWUWw+ETbHVUhK151yQP0upI=; b=ZgG8dsjgRUgIcCJoPQJ8EHpaOQXLk7Mo0om2OXXULE0W2zOUEuWPAl6M2fIxkJRDVt YzAVkkbRSiKquRTKUzGkF4YTOq8Nu0f+oairxj3Y5fZ9DnQmdElKcqzs+DUBCX/l3jvu po5OnCuLmHIDmgLcQq5CUSLsya5plBM/fdaCzhKIHcuLduV2gI+rYC1PrmAXutFLKRe6 +KfBmxylCeHQnZgKDXhL2xNqKQSVVHFeohVCy7BB2e0kvGatQwxQ5LUwetjN9YxwWSFa R4cEIfzpMQKDcTS+QV9rb8RpG1b0ykAOp7mwVUG5R96b5uqJZvp0i79ylzmrK76v8hlg 2Xmg== X-Gm-Message-State: AOAM5307LEkbJKQEatOK0Ax15LEg8PyvDjYKsOCMmwHB1VXsDZeV+HNM c16JVX2TkcauuuM3TQXfRPBMjmA1H0m1Cr0AmhHb+oAC6ECiiIiS X-Google-Smtp-Source: ABdhPJy4MoqjjVFER9Q3A29fT7KyqZMVWhC3JzZBhkhHJIsNEXCJZwXVXHKxKdUQIpn5A1gzPzHWPNS33R1VkB+me10= X-Received: by 2002:a05:6402:1771:: with SMTP id da17mr33200829edb.23.1626684095090; Mon, 19 Jul 2021 01:41:35 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 19 Jul 2021 10:41:23 +0200 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000a6542b05c775e769" Subject: intersection types and null for defaults, properties and return types From: nicolas.grekas@gmail.com (Nicolas Grekas) --000000000000a6542b05c775e769 Content-Type: text/plain; charset="UTF-8" Hi all, I want to bring your attention to a behavior that was mostly overlooked: 1. it is not possible to use an intersection type with an argument that defaults to null 2. it is not possible to use an intersection type with a nullable property (nor to make it default to null) 3. it is not possible to use an intersection type with a nullable return type Actually, 2. was possible until it was "closed" in https://github.com/php/php-src/pull/7254 I reported these behavior and you might find some discussion about it in https://bugs.php.net/81268 Looking at the past discussion on this list ( https://externals.io/message/113712) and at the rfc itself ( https://wiki.php.net/rfc/pure-intersection-types), this was mostly overlooked. That's why I'm posting this message. So that we can have that missing discussion here. To me, we are going to need (userland "we") these capabilities. It's quite surprising to be "forced" to return something, or "forced" to pass a value, when all other types in PHP allow "null". I know about the null pattern, but it is quite uncommon in PHP, because "null" works just great usually. I feel like we "just" need to agree on a syntax to make this possible. It was first suggested in the related PR to use "?A&B" (see https://github.com/php/php-src/pull/6799#issuecomment-804761117) This was rejected by the author with the reasoning that (?A)&B could mean (?A)&B or ?(A&B) or even (?A)|B. I personally don't think this ambiguity exists: (?A)|B is strictly the same as A&B, thus ?A&B cannot also mean A&B, and I don't get how one could take ?A&B for (?A)|B. Another argument is that ?A&B might collide with a future syntax. But I fail to see how. For sure we create examples of such collisions, but they all look constructed to me. Shouldn't we allow ?A&B ? Intersection types look unfinished to me without compat with nullables. Cheers, Nicolas --000000000000a6542b05c775e769--