Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121030 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50108 invoked from network); 10 Sep 2023 14:36:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Sep 2023 14:36:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 102931804AC for ; Sun, 10 Sep 2023 07:36:25 -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, T_SCC_BODY_TEXT_LINE 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-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 10 Sep 2023 07:36:21 -0700 (PDT) Received: by mail-vk1-f176.google.com with SMTP id 71dfb90a1353d-49352e9b416so127863e0c.0 for ; Sun, 10 Sep 2023 07:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694356581; x=1694961381; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jqsV8rXPPbhI2MwJWU/eXGXawULpF6y+0kwfAGxFftc=; b=gjFxfm4axRzBA39J3onv3/ImSldEuOE6mDui0j73He4W7yAVyAUXqkjeRfpthcmx+Q +2r3e7g3JNJ2LFUytHV+0vYdyCd1xdUD8YGaNfAOUOD720C3AJ2kZC+qBScIP9GXw6Ty eNW+eXK9IqRiLdGDAaLagepWckJfOK2jNG/BcrBuyZ4iDsnQF8HXuwbtsP+4wUspJVTc hO9YRfKtINhf1lRGqURccjoaI2mW5jrisL3L2eHi7ywXs43ynOtIV1mdj3lemAyNVi5K PTIpoSi9Gq9PPGRe/Lfw7UKhDrcQY1CcpzzkhBcgogGB4+hD4wJ6hFR1pkgmw/LBoOgl 41qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694356581; x=1694961381; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jqsV8rXPPbhI2MwJWU/eXGXawULpF6y+0kwfAGxFftc=; b=t7NjtW5Sc+SXo6FJV1PpVMKE7e0rFUHpybYsTZmFxdnBapbHdDitDJtxmuJSOX5DbJ ZtaFmFrFyVISeSn+6/I1eEiDnIzH5A+yy96smdFbu2FTM7PHYAXLaHQLhONJTcEpjn+u ZJ5ENHuncfeVxdHpWeORuzA2vGdvhgioDjjEBKzBuTLXQ0l22bll3WNT+RrGKoiUWVXt 5d+98B44SroM4KKy07fXKNnHgaOgfuhQRzrQa5Iq5tJWYNEhT9HcBuIqfyhqeBdlthXV gACNZU3pdKRV0Bjq2NruJCf7ctHuJVh+1Q59PVjyJGD0bbtkbXlfyEQS34TtcGUG/sN6 Sltw== X-Gm-Message-State: AOJu0YwN2f4/wk7g/ShqaPd38mgiEMs8yfrYOOgaRROiK+WBjQCrQKjd zcOEei/mVjg6i5BQ/EOgw71dx7QTiKnB0hpN8wQ= X-Google-Smtp-Source: AGHT+IE0fXMpueGrBGk+L6z2wEgWl2k5zZ2duYLrjXpf+EFTLGNn0dPQQ0POVZ8UkVHCJ4ZM5AyfrMtqf9wUhaCVKNQ= X-Received: by 2002:a1f:2615:0:b0:490:2492:413 with SMTP id m21-20020a1f2615000000b0049024920413mr3602992vkm.1.1694356580698; Sun, 10 Sep 2023 07:36:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 10 Sep 2023 11:35:44 -0300 Message-ID: To: Ilija Tovilo Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000001d8ef20605022291" Subject: Re: [PHP-DEV] [RFC][Draft] Match block From: deleugyn@gmail.com (Deleu) --0000000000001d8ef20605022291 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 8, 2023 at 7:16=E2=80=AFPM Ilija Tovilo wrote: > Hello everyone > > I've been working on match blocks over the last few weeks. > https://wiki.php.net/rfc/match_blocks > > I've already shared it in R11 and got conflicting feedback, which > makes me unsure on how to proceed. We have a few options. > > 1. Add blocks only to match, possibly adding blocks to other > constructs in separate RFCs (the approach of this RFC) > 2. Support block expressions as a language-level concept, analogous to > https://doc.rust-lang.org/reference/expressions/block-expr.html > 3. Do nothing > > The two main complaints/questions I've gotten was whether this > approach is the right one, and whether the syntax can be improved. The > RFC tries to go into detail on explaining the rationale for the chosen > approach. Additionally, it proposes a few alternate syntax options, > although none of them are very satisfactory. > > At this point I'm unsure whether a proposal can satisfy all camps. Let > me know if you have any thoughts/ideas. > > Ilija > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > Hi Ilija, This seems like an interesting subject for the PHP language, but unfortunately doesn't take the direction I would much have preferred. The use of `<-` to denote a different style of return statement in a block feels quite "alien" (for lack of a better word) in the language for me. In addition to that, I'm also not sure if there's anything else in PHP that behaves differently when a return value is expected or not - this is in relation to the difference between `$result =3D match()` vs `match()` witho= ut expecting a result. If there's anything else in PHP that already has a similar behavior, it might be worth adding it to the RFC so that we can relate the subjects. To me it would be much better to stick with the existing language constructs just as-is. ``` { echo "foo branch reached\n"; }, }); // foo branch reached // NULL var_dump(match ('foo') { 'foo' =3D> { echo "foo branch reached\n"; return 'this will be dumped'; }, }); // foo branch reached // string(19) "this will be dumped var_dump(fn () =3D> { echo "auto-capturing short closure invoked\n"; }()); // auto-capturing short closure invoked // NULL var_dump(fn () =3D> { return 'foo'; }()); // string(3) "foo" $foo ??=3D { bar(); }; var_dump($foo); // NULL $foo ??=3D { bar(); return 'baz'; }; var_dump($foo); // string(3) "baz" ``` There's a somewhat related discussion on this RFC https://wiki.php.net/rfc/auto-capture-closure#multi-line_expressions which comes to mind and was just 2 votes short of have been approved. Other good-related RFCs are https://wiki.php.net/rfc/short-match and https://wiki.php.net/rfc/short-functions which creates a really nice symmetry in the language syntax. Ultimately, this is a sad 10-year-long discussion (as summarised here: https://externals.io/message/113740#113833) that seems impossible to move forward within the PHP language. The door of creating of a block with auto-capture look-and-feel much better across many different aspects of the language, but it's always shutdown by enough long-time voters. Overall, between the choice of creating a new syntax that "kind of represents return statements on specific scenarios" or option 3 - do nothing, I would prefer to do nothing until we manage to gather enough voters to overcome the "no-auto-capture" camp. --=20 Marco Deleu --0000000000001d8ef20605022291--