Ferenc Kovacs wrote (on 13/08/2014):
sorry to jump in this late, but I'm not sure that it is a good idea to only
reject the multiple default blocks but keep the ability to have the same
case multiple times:
http://3v4l.org/eZdPU

Multiple cases with the same value are a lot harder to prevent (if not impossible), because there is no requirement for the cases to be static, or of the same type. The spec actually calls this out with a couple of examples: https://github.com/php/php-langspec/blob/master/spec/11-statements.md#the-switch-statement

It would be a bit awkward if this was a syntax error:

switch ( $foo ) {
    case 30:
    case 30:
}

But this was fine:

switch ( $foo ) {
    case 30.0:
    case 30:
    case 10 * 3:
}

And this, which is completely undetectable at parse time:

$bar = 30;
// ... arbitrary amount of code
switch ( $foo ) {
    case $bar:
    case 30:
}

--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to