switch statement and multiple default cases
| From: | Robert Stoll | Date: | Mon, 04 Aug 2014 09:49:41 +0000 |
| Subject: | switch statement and multiple default cases | ||
| Groups: | php.standards | ||
| Request: | Send a blank email to standards-+get-301@lists.php.net to get a copy of this message | ||
Heya,
The spec states "There must be at most one default label." [1] which is
surely the right way to go IMO but not even the PHP implementation (5.5.9)
behaves like this and the following is perfectly valid:
$a=1;
$b=0;
switch($a) {
default:
$b += 1;
break;
default:
$b += 2;
}
echo $b; //output would be 2
Should I report a bug?
Cheers,
Robert
[1]
<https://github.com/php/php-langspec/blob/master/spec/11-statements.md#the-s
witch-statement>
https://github.com/php/php-langspec/blob/master/spec/11-statements.md#the-sw
itch-statement