note 63148 added to control-structures.switch

From: Date: Tue, 14 Mar 2006 17:06:19 +0000
Subject: note 63148 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-105795@lists.php.net to get a copy of this message
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(). ---- Server IP: 66.207.199.35 Probable Submitter: 68.148.210.62 ---- X-Spam-Status: No, hits=4.2 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_40_50,HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- http://master.php.net/note/edit/63148 Del: integrated -- http://master.php.net/note/delete/63148/integrated Del: useless -- http://master.php.net/note/delete/63148/useless Del: bad code -- http://master.php.net/note/delete/63148/bad+code Del: spam -- http://master.php.net/note/delete/63148/spam Del: non-english -- http://master.php.net/note/delete/63148/non-english Del: in docs -- http://master.php.net/note/delete/63148/in+docs Del: other reasons-- http://master.php.net/note/delete/63148 Reject -- http://master.php.net/note/reject/63148 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105795) next »