On Wed, Aug 13, 2014 at 12:22 PM, Rowan Collins <rowan.coll...@gmail.com> wrote:
> 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: > } > > agree, and I thought about mentioning that, but I left that out, because I'm not proposing to remove that ability (and I see more use-cases for that as mentioned in my previous email) but stating that this patch would make an arbitrary distinction between the normal and the default cases. -- Ferenc Kovács @Tyr43l - http://tyrael.hu