Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115540 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 304 invoked from network); 21 Jul 2021 08:24:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jul 2021 08:24:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7A7401804D1 for ; Wed, 21 Jul 2021 01:49: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=-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-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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, 21 Jul 2021 01:49:32 -0700 (PDT) Received: by mail-lf1-f43.google.com with SMTP id q16so2054697lfa.5 for ; Wed, 21 Jul 2021 01:49: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=RB+CZaeQDWogOU3ZA+H0kzOWWvoA1WuYi5NlI1gzW8Q=; b=DQEJhZJI+C9DvAPqsMebDcqQyUGW09rgbhXn5vtAUcwuWuyLVwoseXrWTE8kQ/pvhm rW/Mv25+rCH3KDAonKJRRgAKfzQrEYUZ0wQkHp8hD06ZpwEMKaENvoUFN433JVug0r/B KkODFb/0PCUcuXBoAR+7lbVXWxP3k30kcAQBMjzNGgrQEdiZiyCAgXqMr7B7fE7YAtuf lYNiQK0npu79IsNEY3IboA5CYV/2xaQyut2xf3Sbg0YK/oOupM2ydKFmUaT+xzZTVwgk aaV0fQENeaYoj/NBfttc/ebtMyt27TgpUtSCjV9kT8I4Gls/rGn62L2qIAqjSAunPF2s mgrw== 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=RB+CZaeQDWogOU3ZA+H0kzOWWvoA1WuYi5NlI1gzW8Q=; b=N+UjHw2FkjuSsXT4EV22KNsLOwGSA57xlj4Nu7k7JI1dZOyHaJI3apnt4DTpHL3hc1 nfFT15IE63+u5mTN3NT8/MCh44hqOOCmop3baby/hoDCb3wyBgJ3dblAaicJt8YvR1tk JQ1CaOAfNVpGA28j+cvh3Ai2QM2qo8j/34TIPa8C+29+SH2zCeqLHa5+KLjtyxYLaABl kdNZrSV3FhjPrnl1iF/aUGlSdwiZW4d+GWqdNLS6TeqTdU5296oMxMwLj3AQvWL86rmV n0SgHktoUJO1o4yOQvZQnimbKVlBgOcJVOGSyNhHDKDUoaejvhfVBUAYSEVJuPi7+qva BUhg== X-Gm-Message-State: AOAM530uiHNfDFCK++XtF2PnlC+pzfvAFGuMj6EW3rxuLnomMH2qTHry B4Zisj9mKLzgx7UuEw5oI9z76ZYu2RnBwug/3ZJ42BexBQ== X-Google-Smtp-Source: ABdhPJw4bXJMsgW8rjvUkpPGlfxU267g/u9prRZ9iwhiB7bbfO7H3roFSZQmrPIILSzbb1gHCN760EXmb+HkxyvttL4= X-Received: by 2002:a19:6a09:: with SMTP id u9mr25022854lfu.119.1626857370259; Wed, 21 Jul 2021 01:49:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 21 Jul 2021 10:49:19 +0200 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000a792c805c79e3f14" Subject: Re: [PHP-DEV] intersection types and null for defaults, properties and return types From: guilliam.xavier@gmail.com (Guilliam Xavier) --000000000000a792c805c79e3f14 Content-Type: text/plain; charset="UTF-8" Replying to multiple things: On Mon, Jul 19, 2021 at 8:16 PM G. P. B. wrote: > > And I find it frankly insulting that in the four month this RFC has been > published for discussion, with multiple push backs for voting due to bugs > and me wanting that people know what implementation is - for the most part > - going to land in php-src, this specific point has not been raised. > I'm sorry if you felt it like that (even if maybe not from me personally), as I had the impression that it *has* been raised, several times: - https://externals.io/message/113712#113730 : "Does this miss an opportunity, though? It's useful to be able to write A&B|null." - https://github.com/php/php-src/pull/6799#issuecomment-804761117 : "Is there any reason to not allow ?A&B type?" - https://github.com/php/php-src/pull/6799#issuecomment-805175050 : "However, if I'm not mistaken, you would create the only type that is not nullable. That feels like an unnecessary edge-case. Would it be very difficult to at least allow the union of an intersect type with null?" Even though you replied to each of them (explaining the why, so I didn't add an extra voice then*), that does look like this specific point was actually raised in early discussion? *But I can add my thank you for implementing this feature in the first place! =) On Tue, Jul 20, 2021 at 1:07 PM Nikita Popov wrote: > > I don't think there's been any malicious intent here -- it was obvious to > you and I that not allowing unions implies not allowing nullability, but I > can see how people less familiar with our type system implementation would > not make that connection. After all, we do provide the separate ?T syntax, > even if it is an internal alias for T|null. > > It's an unfortunate fact of the RFC process that concerns are sometimes > only raised when voting starts and people start looking at the > implementation -- or in this case, when they test the implementation after > it has landed... > Agreed to both points. On Tue, Jul 20, 2021 at 7:40 PM Jordan LeDoux wrote: > > For example, in my own projects if I had the need for such a thing, I > would instead use: X&Y&Optional. This would enable me to provide > arbitrarily detailed information about the conditions of the optional > nature of the data and an implementation of it that was aware of the nature > of my program. That can't be easily achieved with nulls. > Nicolas said: "I know about the null pattern, but it is quite uncommon in PHP, because "null" works just great usually." (and I would add that it probably suffers from the lack of generics and/or tagged unions). In retrospect, do you think you would argue against https://wiki.php.net/rfc/nullsafe_operator ? and even https://wiki.php.net/rfc/nullable_types ? On Tue, Jul 20, 2021 at 9:19 PM Deleu wrote: > > I don't know if anyone has offered this before, but if making an exception > for nullable Intersection is on the table, what about putting the null sign > at the end? > > X&Y&Z? > > It doesn't seem ambiguous because PHP defines ?X as nullable X. It doesn't > seem obvious what the ? is doing at the end but at least it doesn't seem > ambiguous. > >> IIRC one reason the prefix syntax was chosen (for PHP) instead of the postfix one (from other languages) is to prevent a potential conflict with hypothetical future generics using a "X" syntax (because "X" would then have been interpreted as a PHP closing tag). On Wed, Jul 21, 2021 at 9:05 AM Nicolas Grekas wrote: > > Thanks Nikita, Joe and the others for opening the possibility of a late > RFC. I'm going to write one down asap! > Thanks, looking forward to the RFC. --000000000000a792c805c79e3f14--