PSR-2 when using alternative syntax for control structures

318 views
Skip to first unread message

Sam Mountford

unread,
Jun 22, 2015, 11:26:46 AM6/22/15
to php-f...@googlegroups.com
If we are using the alternative syntax for control structures which is the case?

a) they are not covered by PSR-2 i.e do what you want
b) only the parts not relating to parentheses apply
c) shouldnt be used if following PSR-2

specifically this line - "The body of each structure MUST be enclosed by braces." - would suggest c but that seems a bit restrictive?

Many thanks

Sam

http://php.net/manual/en/control-structures.alternative-syntax.php

(from the site)

PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

if ($a == 5):
    echo 
"a equals 5";
    echo 
"...";
elseif (
$a == 6):
    echo 
"a equals 6";
    echo 
"!!!";
else:
    echo 
"a is neither 5 nor 6";
endif;

Reply all
Reply to author
Forward
0 new messages