Re: [RFC] Disallow multiple default blocks in a single switch statement

From: Date: Wed, 13 Aug 2014 10:22:34 +0000
Subject: Re: [RFC] Disallow multiple default blocks in a single switch statement
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-76470@lists.php.net to get a copy of this message
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]

« previous php.internals (#76470) next »