Skip navigation.

Ignorance is bliss, defaults are worse

Here's a recent posting to the php-internals newsgroup that made me gasp with shock and horror, then switch over to HomeSite and perform a global search for all declarations of default in switch statements. This is certainly an unpleasant, Titanic-sized iceberg to me.

In my opinion, this should be changed. If you agree, then go to this PHP bug report page and vote, setting "Rate the importance of this bug to you" to high.

Latest (11 Oct 2004): Andi Gutmans agrees that it should be fixed!

From: Andi Gutmans     To: Frank Kromann
Subject: Re: [PHP-DEV] switch() and default:

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 :
>       $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
>
>