Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115482 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83413 invoked from network); 19 Jul 2021 08:56:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jul 2021 08:56:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4C89718053B for ; Mon, 19 Jul 2021 02:21:54 -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.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-4324.protonmail.ch (mail-4324.protonmail.ch [185.70.43.24]) (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 02:21:53 -0700 (PDT) Date: Mon, 19 Jul 2021 09:21:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1626686510; bh=2Hcd7goaluCNKw3llXUwPl11lL34tVKlGlWq0x5KquQ=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=dfKQlR6oIICFerrhsJfZwZXq23sfxQWW6CJu9DPxE1/06pX58a2BosBQIrzdVo3vd pVRKu8tTwvCaCeBYQgsAA5TLQqck6XHy8Q0pAaanqtq4LeBoCB63R/1tpKVbAjtv67 En6iD/ELx56QdC3YLXvV1rSbpGPj2ClnLhM3Eoys= To: Nicolas Grekas Cc: PHP Internals List Reply-To: azjezz Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha256; boundary="---------------------98c981f8a686e5d564cbc8074c025f2a"; charset=utf-8 Subject: Re: [PHP-DEV] intersection types and null for defaults, properties and return types From: azjezz@protonmail.com (azjezz) -----------------------98c981f8a686e5d564cbc8074c025f2a Content-Type: multipart/mixed;boundary=---------------------a41ed6cbdad3a27bbb42405f8c1e8d8e -----------------------a41ed6cbdad3a27bbb42405f8c1e8d8e Content-Transfer-Encoding: quoted-printable Content-Type: text/plain;charset=utf-8 Hello, I personally don't consider a bug, but an expected behavior. when writing: ``` T $x =3D null ``` it is the same as writing: ``` T|null $x =3D null ``` or ``` ?T $x =3D null ``` however, when `T` is an intersection between `X` and `T` ( `X&Y` ), `X&Y $= x =3D null` becomes `null|X&Y $x =3D null`, which is a combination between= union and intersection types, however, as the RFC stats, currently combin= ation between union and intersection types is not support ( hence "pure" )= . for this to be allowed, PHP would need to support combining union and inte= rsection types, preferable using parenthesis ( `X|(Y&Z) $x =3D null` or `(= X&Y)|Z $x =3D null` ). Regards, Saif. =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original M= essage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 On Monday, July 19th, 2021 at 9:41 AM, Nicolas Grekas wrote: > 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 retur= n > = > 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 i= t 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 missin= g > = > 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 possibl= e. 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 t= he same > = > as A&B, thus ?A&B cannot also mean A&B, and I don't get how one coul= d take > = > ?A&B for (?A)|B. > = > Another argument is that ?A&B might collide with a future syntax. Bu= t 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 w= ithout > = > compat with nullables. > = > Cheers, > = > Nicolas -----------------------a41ed6cbdad3a27bbb42405f8c1e8d8e-- -----------------------98c981f8a686e5d564cbc8074c025f2a Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: ProtonMail wsFzBAEBCAAGBQJg9UQYACEJELAOCkaz8cFXFiEEOazMpP0wDQTIQG6zsA4K RrPxwVcijxAAoPsdoekfmURGKj45uGkSbwJFHtFLfq6sxAk60B3Lgk6cS1qU aKOEftfDRVVGtGuv0KdkxKP8aO/v7zHBl2TasOK/lNXx8HjoIdPNPUmvTf06 GN1G0lMHrFWCyNxltnSrPlgv97y6LL/A1/p89LWgKmUjRYcw9iUcLJcc2otA 3yh5O3piuIJYrLuHIc6iXe4dwQGb1LYgIDr5uaEnC2DJS35pY7JHM7jnsqP+ E3Muc7NgtKijh4nWMxeLKs/gU/dP0i0XzRa3TH2i8UL4GFlJAsvvCKEduzO+ WXcrl6c/5RI8FutwkIr9/96OW2gqI4JyY/Fo0rFH+/z6vK1kHleUAVJTLTv3 auPHai8sGsy8rnbaxVfd0GQBoCeDl+Su+RkwkZXzmlDld9DR7a+W/v6y8/rv OYrHcCaoNr1TlgUygFjHA4FA9phqP7ppKMDLPT7r4CvugY4m3m3NUHrzw15k wPrNEJe02UJTsY4Qc7ds+Z+qXHkxgp5Zq3QKT+Re35ILv4OBjmWvDX0qnWEb xQfoCH4I4AK5fFs25BnuSdcCljVKzPxmOZB5B4KjpelUi8yJ478+VlaNt0G4 CT7LnqqkZyMm5g9BOASRA8sO+6kt4nPd66TWsdSfAP2YpSZpx4AFgVPvImr3 SWF+Nuv6+uFZYS9O4O5NVtEE/zdV4VT+Yvc= =sRdA -----END PGP SIGNATURE----- -----------------------98c981f8a686e5d564cbc8074c025f2a--