php - Why does output in an alternate-syntax switch statement cause a syntax error -


i encountered switch statement syntax error described @ http://php.net/manual/en/control-structures.alternative-syntax.php

my ide (phpstorm) detected error, didn't provide useful context correction. code did produce fatal error when including file template.

the manual page's warning:


warning output (including whitespace) between switch statement , first case result in syntax error. example, invalid:

<?php switch ($foo): ?>     <?php case 1: ?>     ... <?php endswitch ?> 

whereas valid, trailing newline after switch statement considered part of closing ?> , hence nothing output between switch , case:

<?php switch ($foo): ?> <?php case 1: ?>     ... <?php endswitch ?> 

the manual page offers no explanation. user comments on page don't explain either; restate whitespace isn't allowed.

why syntax error?

it is.

it's syntax error same reason is:

<?php  $foo = 1; switch ($foo) { ?>     can't here.     <?php     case 1:         echo "i'm one";         break;     case 2:         echo "i'm two";         break; } 

this results in:

[27-jan-2016 22:21:08 europe/berlin] php parse error: syntax error, unexpected ' can't here.', expecting case (t_case) or default (t_default) or '}' in /path/file on line 7

the thing can follow switch case. it's how language works.

the whitespace-specific limitation alternative syntax 1 of reasons is alternative syntax: results in ugly formatting , lacks indentation 1 expect see it.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -