Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115501 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35199 invoked from network); 19 Jul 2021 16:01:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jul 2021 16:01:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C35881804AA for ; Mon, 19 Jul 2021 09:26:11 -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-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.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 ; Mon, 19 Jul 2021 09:26:11 -0700 (PDT) Received: by mail-lj1-f173.google.com with SMTP id b29so6065731ljf.11 for ; Mon, 19 Jul 2021 09:26:11 -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 :cc; bh=AosRvs/mA2m48nLc8DEo8Ik5jZG27wFwxuLXF/hBg7k=; b=lu5Mxdve263UsW0TtmgqZeO964WjVkYcmnCkeXI37ALrfxN/kHXImCT8WEFnWMkjqH ClOFVBWWa5Hpl1CK11fMUZb54fAEhitK0gorxt99xIyyPhL3SJzm5csW2zRM4F6xNvMq u35+lc3uPI/JxuQpx+FdShkgOObGqX13BonOfXvE8jh7EqzS/s3kX2gSGg7cVVtGAKQV H+gkLqgSIuIKmeMFwesWbKlTF7GWIEJsbUOtSwiWVgCdX+lBWI9p0nxmZgKE+NRQU+PQ 1dmA0b0nH9Yl/FtOmrMXY0s54wLOsJspxEjPsoVBICMUxa5LPlNa9qIeRR1d7yydWVwB apyw== 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:cc; bh=AosRvs/mA2m48nLc8DEo8Ik5jZG27wFwxuLXF/hBg7k=; b=afHb9avIgBL5rsvbl81G/S088XeyT41t7HB7l80tjNiUpUSQumpxOu/8LCqG/n80pQ EZW+StISkq71aMqH+NGHocd5IlpIeloZUmU+TajrCNPR1wUPKqEff/7h3dPC0TcNt0uo M+tgRmGoSMHBTswTim9j0ErokER4ROg1SbNbeLi1jILHsSoP4QPyn+ZeEWkhehKarN8V xu6Ij9RyaPJQ7lKY/0trryFjMHtKbEU0v2kmdyBH3ZIoyzbXp3gfHG9ON3PvstsEbXg0 hN6r5spuA5HfWGvtlXvKan9+vg7F+4NPXfbx2atfDTNFSDq3Jwms60qSH3oRouJCXZTv VgRQ== X-Gm-Message-State: AOAM533okvL1Eqd4OhBvJTiQARbbd6XsFHY3pxvXAlfxCxFa2+Eik9qi f4icbmjVXaB1FiuvbPyXYnNsfHZ3G/vRSVjMxA== X-Google-Smtp-Source: ABdhPJzxpOj8IJaNODFb/HOTlhRIOOGFnl+iBtpJN+bcy+UPGcsh0UYzuOG3JTlPug7kqijvVO2X5vINymrd19Yd/pY= X-Received: by 2002:a2e:7612:: with SMTP id r18mr23376867ljc.76.1626711967533; Mon, 19 Jul 2021 09:26:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 19 Jul 2021 18:25:58 +0200 Message-ID: To: Dan Ackroyd Cc: Nicolas Grekas , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000fa0d5005c77c64c5" Subject: Re: [PHP-DEV] intersection types and null for defaults, properties and return types From: guilliam.xavier@gmail.com (Guilliam Xavier) --000000000000fa0d5005c77c64c5 Content-Type: text/plain; charset="UTF-8" On Mon, Jul 19, 2021 at 4:26 PM Nicolas Grekas wrote: > > https://github.com/php/php-src/pull/7259 > Great! Thanks! Interesting how it works out-of-the-box with just this addition in Zend/zend_language_parser.y: ```diff type_expr: type { $$ = $1; } | '?' type { $$ = $2; $$->attr |= ZEND_TYPE_NULLABLE; } | union_type { $$ = $1; } | intersection_type { $$ = $1; } + | '?' intersection_type { $$ = $2; $$->attr |= ZEND_TYPE_NULLABLE; } ; ``` On Mon, Jul 19, 2021 at 5:09 PM Dan Ackroyd wrote: > nicolas-grekas wrote on the PR: > > ?X&Y cannot be confused with > > It confused me. A compiler might understand it, but as a human I have > trouble understanding it. > > Trowski wrote: > > The syntax should be either ?(X&Y) or (X&Y)|null > > Non-ambiguous syntax is much better than ambiguous syntax. > Maybe it's just a matter of habit? For instance I got used to seeing things like `!$x = f()` (e.g. `if (!$x = f()) { throw /*...*/; } /* use $x */`) because some CS consider explicit parentheses in `!($x = f())` redundant (as PHP has a special case that "overrides" the normal precedence `(!$x) = f()` which would be an error). If you first consider `X&Y` as a type "unit", then it makes sense to make it "nullable" by prefixing it with `?`, I think? > > But this discussion is moot for 8.1. > > This limitation might make intersection types not be considered usable > by some projects, but the feature freeze is today. > Which can also be reversed: "The feature freeze is today, but this limitation might make intersection types not be considered usable by some projects"? (playing devil's advocate, I don't master the process) Regards, -- Guilliam Xavier --000000000000fa0d5005c77c64c5--