note 95896 added to control-structures.switch
| From: | lchanady at gmail dot com | Date: | Wed, 27 Jan 2010 17:56:24 +0000 |
| Subject: | note 95896 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165385@lists.php.net to get a copy of this message | ||
Something fairly simple (and maybe obvious) that I didn't see mentioned is that the default
case WILL be executed even if the switched variable does not exist or is undefined.
For example:
<?php
$a = "abc";
$b = "def";
switch($c){
case "a":
echo "a";
break;
case "b":
echo "b";
break;
default:
echo "default";
break;
}
?>
Will output: default
Even though $c was never declared or defined, the default case will still be executed rather than
PHP throwing an error.
----
Server IP: 192.41.40.227
Probable Submitter: 207.68.215.48
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/95896
Del: integrated -- https://master.php.net/note/delete/95896/integrated
Del: useless -- https://master.php.net/note/delete/95896/useless
Del: bad code -- https://master.php.net/note/delete/95896/bad+code
Del: spam -- https://master.php.net/note/delete/95896/spam
Del: non-english -- https://master.php.net/note/delete/95896/non-english
Del: in docs -- https://master.php.net/note/delete/95896/in+docs
Del: other reasons-- https://master.php.net/note/delete/95896
Reject -- https://master.php.net/note/reject/95896
Search -- https://master.php.net/manage/user-notes.php