Re: switch() and default:
| From: | David Vance | Date: | Fri, 08 Oct 2004 05:48:28 +0000 |
| Subject: | Re: switch() and default: | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13224@lists.php.net to get a copy of this message | ||
prints "a" on 4.2.3 Novell, 4.3.3 Linux, 5.0.0 Windows.
On Fri, October 8, 2004 12:21 am, Benj Carson said:
> Hi,
>
> Sorry, I forgot to CC my last reply to the list. I noticed similar
> behaviour and filed a bug report: 30285. The case described in the bug
> report is as follows:
>
> $x = "a";
> switch ($x) {
>
> default:
> echo "default";
> break;
>
> case "a":
> echo "a";
> break;
> }
>
> // Prints "a"
>
> Even though the documentation mentions that default should always be last,
> this is a BC break from 5.0.x and at least 4.3.2.
>
> Thanks,
>
> Benj
>
> On October 7, 2004 10:59 pm, 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 :
>> > $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
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>