PHP 8 · Types and functions

Use match instead of switch

Match with strict comparison. It returns a value and throws if nothing matches.

$label = match ($status) {
    Status::Draft => 'Draft',
    Status::Published => 'Live',
};

Official PHP 8 documentation

More types and functions commands

All types and functions commands · PHP 8 cheatsheet

Was this page helpful?