> Hi internals
>
> I'd like to announce the match expression RFC that replaces the switch
> expression RFC I announced a few weeks ago.
> New: https://wiki.php.net/rfc/match_expression
> Old: https://wiki.php.net/rfc/switch_expression
>
> Due to the feedback I decided to take the RFC in a slightly different
> direction. The main objections were:
>
> 1. It didn't behave like the traditional switch so it shouldn't use
> the switch keyword
> 2. It didn't fix type coercion
> 3. The RFC was poorly structured
>
> In hindsight I understand why I had a hard time writing the RFC. I
> tried making a case against the switch statement while really not
> addressing the switch statement at all. The new RFC proposes a match
> expression that fixes all the objections raised against the switch
> statement. Additionally, match arms can now contain statement lists
> which allows you to use the match expression anywhere the switch
> statement would have been used previously.
>
> While some people have suggested statement lists aren't necessary I
> don't think it makes sense to raise objections against the switch
> statement without offering an alternative.
>
> I also experimented with pattern matching but decided against it. The
> exact reason is described in the RFC.
>
> I'm now confident this is the right approach. I hope you will be
> happier with this proposal.
>
> Happy Easter!
Hello Ilija,

I really like much more this new approach. Only a pair of questions:

Would be posible for blocks to require a return statement instead of raising an 
error?

$y = match($x) {
    0 => ‘a’,
    1 => {
        foo();

        return 'b’; // OK
    }
    2 => {
        var();
    } // Error, return statement is required
}

Would be feasible for the fallthrought problem to use “continue” when you 
really want to chain “cases”?

match ($x) {
    0 => {
        // Only for 0
        continue; // Same as omitting a break in a traditional switch
    },
   1 => {
       // Same for 0 and 1
    }
}

Regards,
Iván Arias.

Reply via email to