- This topic has 3 replies, 1 voice, and was last updated 2 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
PHP 8.0 feature focus: match() expressions
author aside, this site readability is hard as fuck on the eyes
since `match` is similar to control flow structures (yet being an expression) and a language builtin, I think the convention about code style ought to be as `match ()` rather than `match().`
FWIW I think `match (true)` is confusing – why write
$size = match(true) {
$count > 0 && $count <=10 => ‘small’,
$count <=50 => ‘medium’,
$count > 50 => ‘huge’,
};
when you could write the slightly-more-verbose-but-much-more-clear
if ($count > 0 && $count <=10) {
$size = ‘small’;
} elseif ($count <= 50) {
$size = ‘medium’;
} elseif ($count > 50) {
$size = ‘huge’;
} else {
throw new UnexpectedValueException(‘bad’);
}