Alternate syntax is great (dont remove it!), but take care using "else:" after one liners, this wont work:
<?php
if (true):
if (true) print('This results in a parse error (unexpected ":" on line <the_else_line>)');
else:
if (true) { print('Replacing above line with this one also triggers a parse error, curly braces do not help in this case') }
endif; ?>
Either use the alternate syntax on the line in error: <?php if(true):print('This works as its ended by an');endif; ?>
Or write some more code on a newline between the one-liner and the following else (eg. "$var=1;" is enough, even a single semi-colon is, but read below).
A third way is to add a semi-colon to the one-liner, having two if necessary:
<?php
if (true):
if (true) print('This is valid again');;
else:
endif;
if (true):
if (true) { print('This get displayed, even if the doc says the opposite about mixing syntaxes') };
else:
endif;
?>
I can only guess that the added semi-colon makes it work by "closing the if" in a way.
Subsequent semi-colons don't matter, and the semi-colon can be anywhere: at the end of the line, on the following line on its own, or just before the else like ";else". But who would do that anyway.
TL;DR/conclusion:
- avoid mixing alternate syntax and one liners in if/else control structures
- avoid mixing syntaxes inside the blocks (even if it works using this semi-colon trick).
================================
Note to editors: the behaviour described is specifically linked to the use of an else, but this note could also be added to the more general "Alternative syntax for control structures" page as it's also commenting on mixing syntaxes. You know better!