#11447 [Com]: Switch statement sensible for white-space

From: Date: Thu, 22 Jul 2004 07:04:07 +0000
Subject: #11447 [Com]: Switch statement sensible for white-space
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-63314@lists.php.net to get a copy of this message
ID: 11447 Comment by: devis at witcom dot com Reported By: per dot persson at gnosjo dot pp dot se Status: Closed Bug Type: Scripting Engine problem Operating System: Linux (RedHat 6.2) PHP Version: 4.0.4pl1 New Comment: <? switch($var){ ?> <? case "alpha": break; }?> should be equivalent to <? switch($var){ print "\n" case "alpha": break; }?> so why does it work if this <? switch($var){ print " " case "alpha": break; }?> does not work ? Previous Comments: ------------------------------------------------------------------------ [2004-07-21 16:19:23] devis at witcom dot com this problem is still open on 4.3.4 ------------------------------------------------------------------------ [2003-04-03 11:29:47] liamr at umich dot edu Could you guys update the documentation to reflect this? Just reading the sections on switches and the alternate syntax, I thought that this would work.. <?php switch ( $fruit ): ?> <?php case 'pears': ?> I understand Zeev's response to Vlad, and having to do this instead... <?php switch ( $fruit ): php case 'pears': ?> but there's no mention of this in the docs. ------------------------------------------------------------------------ [2001-07-15 16:47:32] zeev@php.net Spaces are indeed significant. Here's why. <? switch($var){ ?> <? case "alpha": break; }?> Is equivalent to <? switch($var) { print " "; break; }?> The two spaces outside the PHP blocks are a valid two character HTML block! Whereas: <? switch($var){ ?> <? case "alpha": break; }?> is equivalent to: <? switch($var){ case "alpha": break; }?> which is valid. Vlad was wrong, the bug is not valid :) ------------------------------------------------------------------------ [2001-06-19 17:16:53] per dot persson at gnosjo dot pp dot se Observe that the spaces are significant. This doesn't work: <? switch($var){ ?> <? case "alpha": break; }?> This does!: <? switch($var){ ?> <? case "alpha": break; }?> I suppose that the interpreter converts text outside <? ?> to echo statements, so that the first code block is equivalent to: <? switch($var){ echo ' '; case "alpha": break; }?> This code block gave the same parse error as the first one! (Expecting T_CASE or T_DEFAULT or '}') ------------------------------------------------------------------------ [2001-06-19 12:29:47] vlad@php.net The bug is valid - if you close and reopen the PHP tags between the switch and the case statement, it is going to bark at you. It shouldn't. This does not work: <? switch($var){ ?> <? case "alpha": break; }?> This does: <? switch($var){ case "alpha": break; }?> Why in the world would anyone do that, is a whole other issue, still they probably expect to be able to do just that. If they can't, we either need to document it as such, (thus re-classify this as documentation problem) or fix it. I do not know what it takes to fix that, but it is a valid report nevertheless. Unbogusifying... ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/11447 -- Edit this bug report at http://bugs.php.net/?id=11447&edit=1

« previous php.bugs (#63314) next »