Cannot Define Multiple Default Branches In a Switch
As of PHP 7.0.0, defining multiple default
cases emits a fatal error. Prior to that, only the last default
case would be executed:
switch (true) {
default:
echo 'not executed';
break;
default:
echo 'executed';
}
See execution result.
Solution
Since only the last default
case ever had an effect, any previous default
cases can be safely removed:
switch (true) {
default:
echo 'executed';
}
Errors or Warnings
- Switch statements may only contain one default clause