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

This is only part of a thread. view whole thread
  110703
June 23, 2020 08:30 benas.molis.iml@gmail.com (Benas IML)
On Tue, Jun 23, 2020, 11:23 AM Björn Larsson larsson@telia.com>
wrote:

> Den 2020-06-22 kl. 18:05, skrev Benas IML: > > > On Mon, Jun 22, 2020, 6:35 PM Björn Larsson larsson@telia..com> > > wrote: > > > >> Hi Ilija,Den 2020-06-18 kl. 22:51, skrev Ilija Tovilo: > >> > >>> Hi Björn > >>> > >>>>> I'd like to announce the match expression v2 RFC: > >>>>> https://wiki.php.net/rfc/match_expression_v2 > >>>> Well one could argue that when working with legacy code containing > >>>> switch statements where one gradually migrates to match, it might be > >>>> easier to have the same separator, i.e. ":". > >>> I think that's somewhat of a moot point. The syntax of match is quite > >>> different (match instead of switch, no case, no break, colon instead > >>> of case, comma instead of semicolon, trailing semicolon). Just making > >>> one of those the same doesn't make a meaningful difference for ease of > >>> migration. > >> Agree on that! One thing though. Is semicolon mandatory or is it > optional > >> like in the first RFC? Feels a bit odd with a semicolon after a curly > >> bracket. > >> > > It's mandatory since it's an expression, not a block. Another example of > an > > expression would be a closure: > > > > ``` > > $fn = function () { > > ... > > }; // a semicolon is mandatory here. > > ``` > > Absolutely so. I was thinking of the case mentioned in v1 RFC when it's > used > as a stand-alone expression. > match ($y) { > ... > }; > Then it's not a standalone expression but a block. In this case, you cannot
add an optional semicolon at all. But this RFC v2 is not proposing to add a block, therefore you won't be allowed to use `match` construct as a standalone expression anyways. ` Optional?
> > r//Björn L >
  110704
June 23, 2020 08:34 tovilo.ilija@gmail.com (Ilija Tovilo)
Hi Benas

>> I'd like to announce the match expression v2 RFC: >> https://wiki.php.net/rfc/match_expression_v2
> Then it's not a standalone expression but a block. In this case, you cannot add an optional semicolon at all. > > But this RFC v2 is not proposing to add a block, therefore you won't be allowed to use `match` construct as a standalone expression anyways.
Using match as a standalone expression is definitely allowed, just like any other expression. // This is fine, the semicolon is required match ($foo) { $bar => baz(), }; Ilija
  110705
June 23, 2020 08:39 benas.molis.iml@gmail.com (Benas IML)
Hey,

On Tue, Jun 23, 2020, 11:34 AM Ilija Tovilo ilija@gmail.com> wrote:

> Hi Benas > > >> I'd like to announce the match expression v2 RFC: > >> https://wiki.php.net/rfc/match_expression_v2 > > > Then it's not a standalone expression but a block. In this case, you > cannot add an optional semicolon at all. > > > > But this RFC v2 is not proposing to add a block, therefore you won't be > allowed to use `match` construct as a standalone expression anyways. > > Using match as a standalone expression is definitely allowed, just > like any other expression. > > // This is fine, the semicolon is required > match ($foo) { > $bar => baz(), > }; >
Yup but it won't return you out of the function. For example, this wouldn't work: ``` function test(int $value): bool { match($value) { 0 => false, 1 => true } } $test = test(1); ``` But it seems by standalone expressions, Bjorn meant your example. Sorry for the confusion, I thought he was referring to blocks.
> Ilija > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >