|
Posted by Jerry Stuckle on 10/23/06 00:35
Pedro Graca wrote:
> Juliette wrote:
>
>>Pedro Graca wrote:
>>
>>>When there is no match for the case expressions and there are several
>>>`default` cases (illegal in C too), the one chosen seems to be the last
>>>and not, as I expected, the first.
>>
>>No matter what, having several 'default:' cases is *always* highly
>>inadvisable.
>
>
> SCNR
> Having several `case CONSTANT:` with the same CONSTANT is ok? :)
>
>
> <?php
> $var = true;
>
> echo "First set: ";
> switch ($var) {
> default: echo 'No variables in the list are'; break;
> case isset($a): echo 'a is'; break;
> case isset($b): echo 'b is'; break;
> case isset($c): echo 'c is'; break;
> case isset($d): echo 'd is'; break;
> }
> echo " set.\n";
>
> $b = $c = 42;
> echo "Second set: ";
> switch ($var) {
> default: echo 'No variables in the list are'; break;
> case isset($a): echo 'a is'; break;
> case isset($b): echo 'b is'; break;
> case isset($c): echo 'c is'; break;
> case isset($d): echo 'd is'; break;
> }
> echo " set.\n";
> ?>
>
> To the Original Poster: don't use this code!
>
Well, it doesn't give an error, but it's operation is specified. So I
suspect if how it works changes you won't be able to do ant hying about it.
The bottom line is - the only defined behavior is to have a single
instance of a specific CONSTANT and a single default.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|