Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109602 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81291 invoked from network); 13 Apr 2020 10:09:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Apr 2020 10:09:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8A1A41801FD for ; Mon, 13 Apr 2020 01:38:24 -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, 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-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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, 13 Apr 2020 01:38:24 -0700 (PDT) Received: by mail-yb1-f177.google.com with SMTP id h205so4897255ybg.6 for ; Mon, 13 Apr 2020 01:38:24 -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=iIKfs9bN/JnKEiMGChIRbDtyI5bHrlm8xmiazJXFhxY=; b=aSsSFqxNICFqInrnHMYMcPPqHcYQx/he4EouYfLDb2PW5xpcT9XylCwdq1C64anH7x SI5XCgvCt1nnF/MXpmSerPilju6bTKIxW9HFLolSRI7Ix2gmsb9kI+NGqJ2ZIGxEYnwA duO9szDluCK1eQpW8UkWjRd2CE3IfvjDeiwIiGQkXgSc43nQp0HpfCH0f1qhQOedFEJy LSWZZc4+awld25VRfOsrqcy4NXPwlYaUO0qHHNo69fd+Yqq/6d/PmKKLm0cAnWtfTVao uGryyaA24KIc+UVNk8s0IKaYzlXJYEr6cCPp6SCPPxabIecfW7uQPH91isiZH/DRolCM aIkw== 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=iIKfs9bN/JnKEiMGChIRbDtyI5bHrlm8xmiazJXFhxY=; b=cFMg5F+nBE1cQzouPU2+TLN0kVMQ8N5fROm8d0Bnky/LcUtkJGD/do3QHNdpJHT2eZ j/RkJbt7MK7/uplSsXeMtKiF8s5q8+okBQGAm+EUlnsKMi0Aud63UyKTgYzMHMDOROXb xKX6Gx+mXvJqGVoM9yuHC7qbvI0CdmDIbCmYTeidJR8b7JwgNJCoCcxJT6xYW0u+nyVz oegsMb2TEkdYDcoPh7vqK2i9x00iV9BH8LJ1dTUPC9XoUmhXGf5Cr6oa0lvj2/0Oh9/e z0bzlhTDTHyc95ve+iiO2f66PFZIq9VFx7ovRxtnf3vZnfSAjAAYxrSjK1ltJk9eH9mC 4a/w== X-Gm-Message-State: AGi0PubVIhxjQDTFW+zMgXeP/Wmo35g0nGFYe2TLg3xWyxtH1Gn8mgrJ AGIIWArIn502ekHVt+BaK4aOQPm9dbTasXOxEFBqjt8e X-Google-Smtp-Source: APiQypK2ha0CubQ0PBWp3a9IExj17jxDpfX1J2yCQnWV7GhY2cXHswkdJd1OlmVghE95HvvVpXk0nFmXShYOIGhikIc= X-Received: by 2002:a25:d411:: with SMTP id m17mr23073749ybf.2.1586767101661; Mon, 13 Apr 2020 01:38:21 -0700 (PDT) MIME-Version: 1.0 References: <6aebe21d-2137-885e-5ee9-99d4f917a7f9@gmail.com> In-Reply-To: <6aebe21d-2137-885e-5ee9-99d4f917a7f9@gmail.com> Date: Mon, 13 Apr 2020 10:38:10 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [DISCUSSION] Match expression From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Rowan > That means if we want to add a way to get a value out of a statement block, > we can't use "return"; and if we want to add explicit fallthrough, we can't > use "continue". And we probably shouldn't do that. return means return from the function, it makes little sense to change it in one specific context. We'd either need a different keyword (like pass) or some syntax that doesn't require a keyword at all (like the block expressions I've mentioned). The same goes for continue. A keyword like fallthrough would be much more fitting. > Again, you skipped the second part of the question - will this make sense to > users? What error message will they get if they write this: > > $x = match($y) { 1 => "Hello", 2 => "Goodbye", 3 => { throw new > Exception; } }; It's described in the RFC: //> Fatal error: Match expressions that utilize the result value can't contain statement lists > So this would be valid PHP? > > $x = match($y) { 1 => "Hello", 2 => "Goodbye" } echo $y; No. A semicolon is needed. Here the semicolon belongs to the assignment, not the match. The parsing would be done somewhat like this: * Expression statement <- Requires a semicolon * Assignment * $x * match The only case where expression statement doesn't require a semicolon is here: * Expression statement <- Doesn't require a semicolon * match Because match is found directly under the expression statement. > I think needing to add a special case to the grammar is a sign that the > proposed syntax doesn't fit well with the rest of the language. I find it odd that people keep referring to Rust but apparently have no clue how it works. This is precisely what they do. https://doc.rust-lang.org/reference/statements.html#expression-statements ExpressionStatement : ExpressionWithoutBlock ; | ExpressionWithBlock A lot of our last conversation is repeating and very little new has been said. The only productive thing is to move on. I think this RFC satisfies your needs. It has some extra parts you don't need, and that's fine. Thanks again for taking the time to read the RFC and provide your feedback! Ilija