switch() and default:
| From: | Frank M. Kromann | Date: | Fri, 08 Oct 2004 03:24:16 +0000 |
| Subject: | switch() and default: | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-13221@lists.php.net to get a copy of this message | ||
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