Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Non Empty Match

<?php

switch ($a) {}

match($b) {};

?>

PHP allows the empty switch: that is, a switch command with an empty block of cases. The whole expression does nothing, and it is as useless as an if statement with an empty block.

The match statement, on the other hand, compiles just like the switch but it also enforces the default case, with an Uncaught UnhandledMatchError: Unhandled match case NULL exception. This one must be caught, or one must add a default case, with a value, to the match to keep it useless.

See Also

PHP Error Messages

PHP Features

Last updated: 10 September 2026