RE: [PHP-DEV] [DISCUSSION] Match expression

From: Date: Sun, 12 Apr 2020 14:18:08 +0000
Subject: RE: [PHP-DEV] [DISCUSSION] Match expression
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-109596@lists.php.net to get a copy of this message
>> Would be posible for blocks to require a return statement instead of raising an error? > >It would be possible for the blocks to return values (though not with >the return keyword). I've created a small prototype a few weeks ago: > >``` >$result = match ($x) { > 0 => { > echo 'Foo'; > echo 'Bar'; > 'Baz' > }, > ... >}; >``` > >íE»ÚÚ !è &K[ >¬https://github.com/php/php-src/compare/master...iluuu1994:block-expression >Heavily inspired by Rust: >https://doc.rust-lang.org/reference/expressions/block-expr.html > >While this would perfectly solve the problem perfectly it feels a >little foreign in PHP. Either way, this is something that can be >discussed an implemented in a separate RFC. My only concern about blocks is that I fell a bit odd that they can only be used under some circustances. I think I would prefer to simply do not include them for now, and discuss these “block expressionsâ€� in another RFC as they seem to be an independent language feature. Regards, Iván Arias.

« previous php.internals (#109596) next »