Changes between Initial Version and Version 1 of Ticket #27882, comment 82
- Timestamp:
- 06/02/2014 05:03:45 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #27882, comment 82
initial v1 4 4 The order may not matter but makes it (much) harder to read/follow when `default` is not at the bottom. Same for the unreachable `break;` after `return` and `die()`. As far as I remember these were added for readability as switch() is one of the "harder to read" constructs, especially for inexperienced users. (Omitting a `break` merges the cases, some people miss or misunderstand that). 5 5 6 I don't particularly mind either way, but maybe we need to add some rules for `switch()` to the coding standards. Few years ago here were some.6 I don't particularly mind either way, but maybe we need to add some rules for `switch()` to the coding standards. Few years ago there were some. 7 7 8 Not sure we need a "demonstration test". Also it is not complete: it doesn't test the default case. 8 Not sure we need a "demonstration test". Also it is not complete: it doesn't test the default case. A better demo would be something like: 9 10 {{{ 11 function _switch_order_helper( $var ) { 12 switch ( $var ) { 13 default: 14 $return = 'default'; 15 break; 16 case 1: 17 $return = 'case 1'; 18 break; 19 } 20 21 return $return; 22 } 23 24 function test_switch_order() { 25 $this->assertEquals( 'case 1', _switch_order_helper( 1 ) ); 26 $this->assertEquals( 'default', _switch_order_helper( 2 ) ); 27 } 28 }}}