Re: switch() and default:
| From: | Andi Gutmans | Date: | Fri, 08 Oct 2004 15:52:54 +0000 |
| Subject: | Re: switch() and default: | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13235@lists.php.net to get a copy of this message | ||
I will look into the reason this seems to have changed.
However, I can assure you that from day 1 this was not supposed to work and was documented as such for years already (since the days of PHP 3). If it worked at some point then it was by chance!
Andi
At 05:31 PM 10/8/2004 +0200, Sascha Schumann wrote:
Andi,from the feedback it is obvious that the engine supported defaults at places other than the bottom.In all switch-supporting languages I know, it is possible to do this:switch ($expr) { default:/* handle everything EXCEPT "foo" and "bar" *//* fall-through */case 'foo': case 'bar':/* handle everything */ break; }Why should the support of this be discontinued?- SaschaOn Thu, 7 Oct 2004, Andi Gutmans wrote:It's always been like that and has been documented for ages in the manual. Andi At 08:24 PM 10/7/2004 -0700, Frank M. Kromann wrote:Hello Everyone, I just discovered a small thing in the switch() statement. The position of the default: clause has to be at the end of the code: $a = 1; switch ($a) { default : case 0 :-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php$b = 1; break;case 1 :$b = 2; break;} echo $b; // should print 2 but it prints 1 $a = 1; switch ($a) { case 1 :$b = 2; break;default : case 0 :$b = 1; break;} echo $b; // prints 2 as expected. This is tested on Linux with PHP5 CVS-HEAD What changed ? - Frank -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php