Glossary

Match Expression (PHP 8)

Match expression is a PHP 8.0 alternative to switch with strict comparison (===), no fall-through, and mandatory exhaustiveness. It returns a value rather than executing statements.

Switch vs Match

// switch — loose, fall-through, no return value
switch ($status) {
  case 'active': $label = 'Active'; break;
  case 'banned': $label = 'Banned'; break;
  default: $label = 'Unknown';
}

// match — strict, no fall-through, returns value
$label = match($status) {
  'active'               => 'Active',
  'banned'               => 'Banned',
  'pending', 'unverified' => 'Waiting', // multiple conditions
  default                => 'Unknown',
};

Advantages