Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109603 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94903 invoked from network); 13 Apr 2020 12:16:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Apr 2020 12:16:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BCE931804DD for ; Mon, 13 Apr 2020 03:45:23 -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-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 03:45:23 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id z6so9515647wml.2 for ; Mon, 13 Apr 2020 03:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=g6Avtyl/uTO1SS69RPuP9YCGEoQCngcL2r9jTNqMzlU=; b=rBe4Ip+6UD4OpEOsQC127LFXRGr/vriy1FqIkq1XGjxN/AvFS+qx1iRQFIBo5dhzEO fkcuXCupU84FJvuDMun0h/tYtDIpqNrdNMthOUtLq84vy/pN9ZOnGyI391VYemXs97N5 ft7X6DSPsIBoX5IdQm1LL9tKYTIW5Ye/H0MVJKICSGv1xfw+ygvCtovaAw3MLBrnxKDo IoKqF1g8p3jQXtKpnYniAS4BZuNaBBYLMl3Q4Z5Cg3DrPL/bht7qahgw62pb3gSnhMPc SCFeu7xnq7rPq2wMl6Hb5PtYqn49SSraZvFMx8NvgZgTKphhdcyLKg8ZgdL0kfve9KvQ 8J8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=g6Avtyl/uTO1SS69RPuP9YCGEoQCngcL2r9jTNqMzlU=; b=bZxJDw49PVjYwku/C6GtPZDXv9x2UrtbIXX1qvoJcL9AzGHNS0T25j1P1Q/byzdkZu agGHA1o1N60aTT/nmvFi2uU/5D/uPnRNbsluHjOJw622tjfu9AfdLFZUAQml6JSFvfmO 6eJMaQZ6CuKo57REL7VvxeCe2U6LsWK29TrQ3MzQ2j1zJM6QLpNhvaLRUlGqJwRx+0Ci WQLF8L6X1qyqg6xVur2VD/Kdu+W9R/cacyiSzhc0jxCOf99ME8p2g/flZF9ICGhbvaoj DuZ2EmXMmZc5+f16NgJ2gYEgANHAi4viaI2nsnY4YRZJlUow4un/MLhS/3OPW2xbUsEz yW3Q== X-Gm-Message-State: AGi0PuYCUOf5CLTU+3ihVgbFjfx2iqySZZg4OMmkwZZkLtmsI72Zimbw eXfOrZbxks0uGaGuqivso2TV3BKR X-Google-Smtp-Source: APiQypK4TK7+vBgmsH2Sd7IZZsgXGtz3iGIG86/OfwNSFKQNMInkVJAjTwB09hDIQtcfl31kn2eDzA== X-Received: by 2002:a1c:197:: with SMTP id 145mr17673211wmb.42.1586774721761; Mon, 13 Apr 2020 03:45:21 -0700 (PDT) Received: from [192.168.0.12] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.gmail.com with ESMTPSA id q187sm14244701wma.41.2020.04.13.03.45.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Apr 2020 03:45:21 -0700 (PDT) Date: Mon, 13 Apr 2020 11:45:18 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: <6aebe21d-2137-885e-5ee9-99d4f917a7f9@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: <5071DCCE-4572-4B1F-A50B-832C5EA74795@gmail.com> Subject: Re: [PHP-DEV] [DISCUSSION] Match expression From: rowan.collins@gmail.com (Rowan Tommins) On 13 April 2020 09:38:10 BST, Ilija Tovilo wr= ote: >It's described in the RFC: > >//> Fatal error: Match expressions that utilize the result value can't >contain statement lists Thanks, I missed that=2E Reasonably clear, I guess, although I imagine the= re'll be questions on Stack Overflow asking what a "statement list" is=2E >> So this would be valid PHP? >> >> $x =3D match($y) { 1 =3D> "Hello", 2 =3D> "Goodbye" } echo $y; > >No=2E A semicolon is needed=2E Here the semicolon belongs to the >assignment, not the match=2E=20 =2E=2E=2E >The only case where expression statement doesn't require a semicolon is >here: > >* Expression statement <- Doesn't require a semicolon > * match Right, so I go back to my earlier point that there are basically two forms= of match proposed: - one where you can use it anywhere an expression is expected, with no sta= tement blocks - one which can be used as a standalone statement, which can contain state= ment blocks, and which doesn't need a trailing semicolon >> 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=2E > >I find it odd that people keep referring to Rust but apparently have >no clue how it works=2E This is precisely what they do=2E > >https://doc=2Erust-lang=2Eorg/reference/statements=2Ehtml#expression-stat= ements I didn't mention Rust, and am fully aware that I don't know how its syntax= works=2E What I said was that the proposed syntax doesn't fit into PHP eas= ily=2E Two things stand out to me following that link: Firstly, block expressions are a foundational part of the Rust language, n= ot a special case used in only one place=2E They're used as the basis for e= verything from if statements to async blocks, all of which evaluate to a va= lue=2E That's a really neat design feature, but not something that exists i= n PHP=2E It also makes the semicolon rule somewhat more natural: it makes *all* the= control flow blocks in Rust feel more natural to developers coming from ot= her languages=2E It's not an ad hoc rule for one expression, it's a general= rule across the language=2E Secondly, the page you linked calls out an ambiguity caused by omitting th= e semicolon, which would apply equally in PHP: match($x) { 1 =3D> ['foo', 'bar'] } [0]; It then explains the important restriction of only omitting the semicolon = if the result is void/null rather than a concrete value=2E An equivalent in= PHP would be to only allow omitting the semicolon if every arm of the matc= h is a statement list, further distinguishing the expression and statement = forms=2E > I think this RFC >satisfies your needs=2E It has some extra parts you don't need, and >that's fine=2E Just to be clear, that may be fine with you, but if I had a vote, I would = probably vote no to the current proposal, because I actively dislike the pr= oposed syntax and semantics of statement blocks=2E They "poison the barrel"= for me=2E That's a real shame, because I really like the core of the propo= sal=2E Regards, --=20 Rowan Tommins [IMSoP]