php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67504 Alternative switch syntax - error when case not in same block with switch
Submitted: 2014-06-23 23:48 UTC Modified: 2014-06-24 00:08 UTC
From: lightnb at bellsouth dot net Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.5.13 OS: Ubuntu 14.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lightnb at bellsouth dot net
New email:
PHP Version: OS:

 

 [2014-06-23 23:48 UTC] lightnb at bellsouth dot net
Description:
------------
My actual version is 5.5.9-1ubuntu4, it wasn't on the list. This is the Ubuntu package version on Ubuntu 14.04.

The following code throws a parse error on the second line. The error is:
"syntax error, unexpected ' ', expecting endswitch (T_ENDSWITCH) or case (T_CASE) or default (T_DEFAULT)"

<?switch($MyVar):?>
   <?case '1':?>
      Step One
   <?break;?>
   <?case '2':?>
      Step Two
   <?break;?>   
<?endswitch;?>

It appears that the closing tag trips up the parser which it should not do when using the alternative switch syntax.

Using the following syntax (putting the first case in the same PHP block as the opening switch) works correctly:

<?switch($MyVar):
   case '1':?>
      Step One
   <?break;?>
   <?case '2':?>
      Step Two
   <?break;?>   
<?endswitch;?>

Test script:
---------------
<?switch($MyVar):?>
   <?case '1':?>
      Step One
   <?break;?>
   <?case '2':?>
      Step Two
   <?break;?>   
<?endswitch;?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-23 23:57 UTC] aharvey@php.net
-Type: Bug +Type: Documentation Problem -Package: *General Issues +Package: Documentation problem
 [2014-06-23 23:57 UTC] aharvey@php.net
This works OK without the indentation (cf http://3v4l.org/Lj7L7): the issue is that the indentation before the case statement effectively puts an echo in between the switch and the case, which is invalid.

I'll see if I can tighten up the alternative syntax documentation to mention that.
 [2014-06-24 00:08 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=333913
Log: Add a cautionary note about switch/case and whitespace.

Fixes doc bug #67504 (Alternative switch syntax - error when case not in same
block with switch).
 [2014-06-24 00:08 UTC] aharvey@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: aharvey
 [2014-06-24 00:08 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 13:00:02 2026 UTC