UnhandledMatchError
PHPERRORCommonType
No match arm matched the value (PHP 8.0+)
Quick Answer
Always add a default arm to match expressions that handle external or dynamic values.
What this means
Thrown (PHP 8.0+) when a match expression has no matching arm and no default arm. Unlike switch, match is strict (===) and raises UnhandledMatchError rather than silently falling through.
Why it happens
- 1match() receives a value not covered by any arm and no default arm is present
- 2Strict type mismatch — e.g. match("1") with arms for 1 (int) not "1" (string)
Fix
Add a default arm
Add a default arm
$result = match($status) {
'active' => 'green',
'inactive' => 'grey',
'banned' => 'red',
default => throw new \InvalidArgumentException("Unknown status: $status"),
};Why this works
default catches all unmatched values. Throwing an exception in default makes unexpected values immediately visible rather than silently ignored.
Code examples
Triggerphp
$x = 4;
match($x) {
1 => 'one',
2 => 'two',
}; // UnhandledMatchError: Unhandled match casematch vs switch — strict comparisonphp
match("1") {
1 => 'int one', // 1 !== "1" — does not match
default => 'no match',
};Same error in other languages
Sources
Official documentation ↗
PHP 8.0 Manual
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev