Interview frequency: …
Short answer
match is an expression that directly returns a value, uses strict comparison (===), needs no break statements, and throws UnhandledMatchError if no case matches.
Explanation
The traditional switch statement uses loose comparison (==) and requires a break after each case to prevent fallthrough. The match expression adds concise, safe, functional syntax with strict type matching and directly returns the result for assignment to a variable.
Code example
$statusText = match ($code) {
200, 201 => "Success",
400 => "Bad Request",
404 => "Not Found",
default => "Unknown Status",
};Common mistakes
- Forgetting to provide a default case in a match expression when not all possible cases are covered.