[thelist] Alternative Control Structure Syntax in PHP

Max Schwanekamp lists at neptunewebworks.com
Tue Aug 29 13:22:22 CDT 2006


> From: Hershel Robinson
> <?php if ($a == 5): ?>
> A is equal to 5
> <?php endif; ?>
>  >   we always discourage the use of : as per recommendations 
> of PHP team
>  > and also due to the fact that this syntax is not folded 
> properly in  > several editors
> How do people feel about this? I am writing coding guidelines 
> for a team and I must decide whether or not to allow this 
> syntax. I personally like it in cases as above where the 
> block extends beyond the ending ?> tag.

I rarely see that syntax in use, and never use it myself.  Seems like a
holdover from the days when PHP was competing directly with ASP/VB.  Most
editors will match brackets for the usual syntax, and the "endif" still
doesn't say *which* "if" it's ending.  A possible compromise for when you
simply must mix PHP and HTML:
<?php if ($a == 5) { ?>
<p>A is equal to 5</p>
<?php } //if($a==5) ?>

This too is not without problems, but it works across editors and highlights
the "endif" idea for that little block.

-- 
Max Schwanekamp
NeptuneWebworks.com





More information about the thelist mailing list