note 63148 deleted from control-structures.switch by bjori
| From: | bjori@php.net | Date: | Tue, 11 Apr 2006 22:36:51 +0000 |
| Subject: | note 63148 deleted from control-structures.switch by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107817@lists.php.net to get a copy of this message | ||
Note Submitter: nobody at example dot com
----
A warning for anyone who uses the alternative syntax for the switch statement: beware of your
whitespace usage! I tried submitting this whacky behaviour as a bug, but got rejected for a pathetic
reason. View <a href="http://bugs.php.net/bug.php?id=36729">bug
#36729</a> for more details (as well as <a href="http://bugs.php.net/bug.php?id=25667">bug
#25667</a>).
The short version of it is this:
<?
// this works because there is only a newline between
// the switch() and the 'case' statements
$var = 'one';
?>
<? switch($var): ?>
<? case 'one': ?>
<p>switch found one</p>
<? break; ?>
<? case 'two': ?>
<p>switch found two</p>
<break; ?>
<? default: ?>
<p>switch found something else</p>
<? endswitch; ?>
<?
// this doesn't work, because html is not allowed between
// the switch() and the 'case' statements. it's ridiculous,
// as whitespace should be ignored but is not. apparently
// this will never get fixed. another 'yay' for php.
$var = 'one';
?>
<? switch($var): ?>
<? case 'one': ?>
<p>switch found one</p>
<? break; ?>
<? case 'two': ?>
<p>switch found two</p>
<break; ?>
<? default: ?>
<p>switch found something else</p>
<? endswitch; ?>
So remember, no putting tabs or spaces before your first 'case' statement when using the
alternative syntax for switch().