Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109703 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29562 invoked from network); 19 Apr 2020 12:08:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Apr 2020 12:08:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 913391804CD for ; Sun, 19 Apr 2020 03:39:05 -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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 ; Sun, 19 Apr 2020 03:39:05 -0700 (PDT) Received: by mail-wr1-f48.google.com with SMTP id j2so8332463wrs.9 for ; Sun, 19 Apr 2020 03:39:05 -0700 (PDT) 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=uwlHlWxKHTGaAp/7aUqn0hWFvITHvoutIWF29Gx1U7Q=; b=UG+EjxLH3Igcz1rd9IHK0B2nHMxUHSA15AvmtZ8wV0rTCOD1XZgb6ppGlNHa/Y90H2 fJ2eVPB/80tiIrkH5aWfnT44L2yZw97eAawruMV72/8FAKrPrI9DKl31Lz5apr73bNCf qceYfcrXewosUxgdgw7dkGq8I6ooFwpC7J8a5DNpdvgbasIePzIhLgCXHq2TPtvF27ih qNCTAPLf2cHR4BYvR/pjEhuQAKkzgpemnbgxEEpFZW/dYIsN3uXzyUE85kdmORnOz8Xh Ww+UwDA/0irC7uAc0rlxlVov3+aPZGfa+Dei2wvSnYs1+EWEanMn1ZtQu2S8qGemASJh g7Mg== X-Gm-Message-State: AGi0PuZ/M5zElraWolE5bDSTqDqnOe37DxLOL00uA8zDBF3/gOUBSnpN WlEVP2ZQuEcCAE/pvVKqL8kN29kZD4FdDnsT4WE= X-Google-Smtp-Source: APiQypKcF5t0lL5ZzhkUQ3gKs2yB3LA5UAeMi4P7xAmeAzoATnadcqHEVl1wPF9bTXbwkT7sxgyHxciSzyknVxMTtPk= X-Received: by 2002:adf:8b45:: with SMTP id v5mr14109005wra.175.1587292740728; Sun, 19 Apr 2020 03:39:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 19 Apr 2020 12:38:49 +0200 Message-ID: To: Ilija Tovilo Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [DISCUSSION] Match expression From: jakob@givoni.dk (Jakob Givoni) Hi Ilija, On Sun, Apr 12, 2020 at 2:16 AM Ilija Tovilo wrote: > > I'd like to announce the match expression RFC that replaces the switch > expression RFC I announced a few weeks ago. > New: https://wiki.php.net/rfc/match_expression > Old: https://wiki.php.net/rfc/switch_expression I know I'm a little late to the game and sorry for that, but I didn't have time to thoroughly read the proposal earlier. And again, sorry if it's just me going "blind" but I can't find anything explaining what will happen if there is more than one matching arm? I imagine that since the case of no matching arms will throw an UnhandledMatchError exception, having several matching arms will also complain that something looks wrong? However, that will require all the arms to be evaluated every time, even after a match is found, which might not be the most optimal approach. Then again, if not all arms might be evaluated, the order of evaluation is important (since several matching arms could be found), but it's not stated in the RFC if the order of evaluating arms follows the order they are written, or if the compiler/interpreter is allowed to choose another order if it thinks it might find the matching arm sooner? --- To recap, perhaps you can answer these questions clearly in the RFC: - What happens if more than one arm is matching? - In which order are the arms evaluated (in case order is significant) - is it predictable or an implementation detail that the developer should not rely on? - Can the left side of the arms be any expression or only "constant-style"? (If expressions are allowed, order also becomes significant) Apart from these questions, it might be a good idea to evaluate the impact of the Backwards Incompatible Changes by checking top repositories for the use of the new keyword "match" in classes and namespaces etc. Finally, I find the mixing of match as expression and match as stand-alone statement unfortunate. I understand very well the closeness between the two, but I also think that those are two quite different use-cases which presume different intentions and expectations for behavior: For example, when using "match" as an expression and assigning the value to a variable (the second example at the top of the RFC - as an alternative to hash maps and nested ternary operators) it's natural to assume that one and exactly one arm must match. Otherwise the variable will end up with an ambiguous or undefined value. I also would consider it "flippant" and not a common need to use block statements as the arms in this case! On the contrary, when using "match" as a statement (much more like "switch" and like "if"), there is no problem if no arms match, and if several arms match, why not execute all of them? Also, block statements in the arms would be natural and common. Would it be a possibility to separate the two into different RFC's? Personally I find the expression style most useful and I'd be happy to see this part passed, which I think would be relatively easy since a lot of the more complex points could be evaded: Block statements, return statements, break/continue statements (which I don't really understand in the context of an expression) and the trailing semicolon issue. Hope the feedback was useful and best of luck with the RFC! Jakob