PHP theorytheory 0/50 · 0%
Fundamentals · medium

23. Match Expressions

Strict, expressive branching.

The match expression (PHP 8.0) compares subjects using strict (===) comparison and returns a value, unlike switch which falls through and uses loose comparison. Each arm maps one or more comma-separated conditions to a result.

match throws an UnhandledMatchError if no arm matches and there is no default case, catching bugs that switch would silently ignore.

Check your understanding

  1. 1. How does match compare values, by default?

  2. 2. What happens if no match arm applies and there's no default?