Re: unexpected switch behavior
| From: | Rasmus Lerdorf | Date: | Mon, 07 Oct 2002 23:06:20 +0000 |
| Subject: | Re: unexpected switch behavior | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119156@lists.php.net to get a copy of this message | ||
No, it wouldn't skip it since it is just a warning and you are effectively
doing a switch(NULL) which is still valid. Since you don't have a
specific case for NULL you get the default.
-Rasmus
On Mon, 7 Oct 2002, Thoenen, Peter Mr. EPS wrote:
> Hello,
>
> Getting unexpect behavior for the following switch statement
>
> # snippet in example.php
>
> switch ($_GET['var']){
> case 1:
> echo 'foo';
> break;
> default:
> echo 'bar';
> }
>
> When I enter the following url:
>
> http://sub.domain.tld/example.php
>
> Page displays:
>
> Notice: Undefined index: var in \htdocs\example.php on line 19
> bar
>
> The unexpected behavior is the displaying of the word bar. What I expected
> was just the error message. If the switch variable is illegal (or undef),
> shouldn't it skip the entire switch statement as opposed to executing it
> using the default case.
>
> Thanks for any clarification on this,
>
> -Peter
>
>
> ##################################
> Peter Thoenen - Systems Programmer
> Commercial Communications
> Camp Bondsteel, Kosovo
> ##################################
>
> "Stumbled Upon"...heh (Score:5, Funny) /.
> by $carab on 23:00 23 August 2002 (#4131637)
>
> "ForensicTec officials said they stumbled upon the military networks about
> two months ago, while checking on network security for a private-sector
> client."
>
> Someone new to a Dvorak probably tried to type in "lynx
> http://www.google.com" but instead got "nmap -v -p
> 1-1024 -sS -P0 army.mil
> -T paranoid".
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>