PHP 8.0 match() expressions
Blog post from Upsun
PHP 8.0 introduces the match expression, a modernized branching logic construct that enhances the capabilities of the traditional switch statement by offering strict equality comparison, eliminating fall-through, and returning a value. Unlike switch, match evaluates with strict equality (===) rather than loose equality (==), ensuring type matching, and is designed to handle single expressions rather than multi-line statements, encouraging the use of functions for complex logic. It is exhaustive, meaning if no match is found and there is no default case, an error is thrown, preventing silent null assignments. The match construct supports compound branches for OR-like behavior and can be used with a boolean condition for more complex scenarios, promoting clean, well-factored, and testable code.