On Tue, 23 Jun 2020 at 09:54, Björn Larsson <bjorn.x.lars...@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]

Reply via email to