Re: [DISCUSSION] Match expression

From: Date: Sun, 12 Apr 2020 12:47:47 +0000
Subject: Re: [DISCUSSION] Match expression
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-109594@lists.php.net to get a copy of this message
Hi Iván > 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' }, ... }; ``` 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. > Would be feasible for the fallthrought problem to use “continue” when you really want to > chain “cases”? Yes, that would be feasible. I personally just don't see a huge benefit of fallthrough. If we ever implemented pattern matching it could become unfeasible again (or at least require additional sanity checks): ``` match ($value) { Foo { foo: $foo } => { fallthrough; } Bar { bar: $bar } => { // $bar is unbound } } ``` Ilija

« previous php.internals (#109594) next »