Re: [DISCUSSION] Match expression

From: Date: Sun, 12 Apr 2020 20:16:02 +0000
Subject: Re: [DISCUSSION] Match expression
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-109599@lists.php.net to get a copy of this message
Hi Rowan > Can match arms contain other flow control, such as "return" or "continue"? Yes and yes. They behave exactly the same as in the switch. This should definitely be described in the RFC. > Can I mix a bare value and a block as arms of the same match, or does the whole construct need > to be in either "expression form" or "statement form"? Yes, you can mix blocks and expressions given you don't use the return value of the whole match expression. > Can I omit the trailing semicolon even in "expression form" Yes. To clarify what's going on here: There's no statement variant of the match expression. PHP already allows using any expression as a statement. https://github.com/php/php-src/blob/422c8390a01ce9b6f612e0183bd0e4500c0608be/Zend/zend_language_parser.y#L446 That's why you can do something like 10 + 20;. PHP will just discard the result value. The same thing is happening here. The only difference is that I added a rule to the grammar to allow dropping the semicolon in this case because I noticed that I kept forgetting to add it in my tests. > We can always add statement blocks in later I think we'll never completely agree on this point, and that's fine. As mentioned in my announcement IMO it doesn't make sense criticizing the switch statement but then not offering an alternative. Thanks for your input! Ilija

« previous php.internals (#109599) next »