Switch statements may only contain one default clause

Description

The switch expression uses cases and a default entry. Cases are matched against the parameter variable, and when all of them fail, the default case (sic) is used. This also means that there can be only one defaut entry, as it will be used after all the cases.

When several default cases are spotted, PHP stops compilation.

Note that there is no error message for multiple identical cases: in such situations, the first one is used.

Example

<?php

switch($a) {
    default:
    default:
}

?>

Solutions

  • Remove all defaults but one.