Re: [PHP-DEV] Re: [RFC][DISCUSSION] Match expression v2

This is only part of a thread. view whole thread
  110702
June 23, 2020 08:30 tovilo.ilija@gmail.com (Ilija Tovilo)
Hi Björn

>> I'd like to announce the match expression v2 RFC: >> https://wiki.php.net/rfc/match_expression_v2
> Absolutely so. I was thinking of the case mentioned in v1 RFC when it's used > as a stand-alone expression. > match ($y) { > ... > }; > ` Optional?
In this RFC the semicolon is required. Many people thought the grammar rules for the optional semicolon were confusing which is why I dropped that feature in this RFC. Ilija
  110706
June 23, 2020 08:54 bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=)
Den 2020-06-23 kl. 10:30, skrev Ilija Tovilo:

> Hi Björn > >>> I'd like to announce the match expression v2 RFC: >>> https://wiki.php.net/rfc/match_expression_v2 >> Absolutely so. I was thinking of the case mentioned in v1 RFC when it's used >> as a stand-alone expression. >> match ($y) { >> ... >> }; >> ` Optional? > In this RFC the semicolon is required. Many people thought the grammar > rules for the optional semicolon were confusing which is why I dropped > that feature in this RFC. > > Ilija
Ok, thanks for the clarification. The reason for me to bring this up is that I was pondering on if this is the only place in PHP where a semicolon is required after a curly bracket when not used in an expression. If so I a counter argument could that it it is confusing for programmers, not so privy to all the ins and outs of PHP. Anyway, maybe a feature to consider for a future 8.1 RFC. r//Björn
  110709
June 23, 2020 12:09 rowan.collins@gmail.com (Rowan Tommins)
On Tue, 23 Jun 2020 at 09:54, Björn Larsson larsson@telia.com>
wrote:

> > Ok, thanks for the clarification. The reason for me to bring > this up is that I was pondering on if this is the only place in > PHP where a semicolon is required after a curly bracket > when not used in an expression. >
Two things: - as proposed here, match is *always* an expression; it just happens that PHP lets you throw away the result of an expression, so "match($x){};" is a valid statement for the same reason "42;" is a valid statement - as Ilija mentioned, ending a statement with an anonymous function also leads to the combination "};" function returnsFunc() { return function() { echo "Hello, world!\n"; }; } function returnsMatchResult($x) { return match($x) { 1=> "Hello", 2=>"world" }; } I'd also note that while there aren't currently many cases where it would be ambiguous whether a statement or expression was intended, new ones might be added in future. For instance, post-fix conditionals (like in Perl and Ruby) would give us match($x) { ... } if $condition; This kind of syntax short-cut tends to end up with complex rules of "it's optional except when it's not", which I'm personally not a fan of. Regards, -- Rowan Tommins [IMSoP]