PHP 8.0 feature focus: match() expressions

  • This topic has 3 replies, 1 voice, and was last updated 2 months ago by muglug.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2425
    autopoietic_sapien
    Participant

    PHP 8.0 feature focus: match() expressions

    #2426
    afuiasdyfuiay
    Guest

    author aside, this site readability is hard as fuck on the eyes

    #2427
    helloworder
    Guest

    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().`

    #2428
    muglug
    Guest

    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’);
    }

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.