K
K
koliane2018-04-04 16:06:16
PHP
koliane, 2018-04-04 16:06:16

Why is the alternative syntax of php control structures sometimes used in layout?

Why is the alternative syntax of php control structures sometimes used in layout? For example,

if (..):
    ....
endif;

After all, the usual syntax, with brackets, is more convenient:
if (..) {
    ....
}

The same goes for other structures (foreach-endforeach, etc.).
Also, the brackets for the regular syntax highlight almost all editors, but not for the alternative.
What is the reason for using alternative syntax in layout?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
tigra, 2018-04-04
@tigroid3

well, because it's more readable

<?php if ($test == 1): ?>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
<?php endif ?>

than where, all content must be output through echo, for this, either such a construction, or template engines
<?php if ($test == 1) {
   echo "<div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>
   <div>some text</div>";
}

?>

P
profesor08, 2018-04-04
@profesor08

Because the code looks neat and the automatic formatting works great. endif, endfor, endforeach perfectly indicate which block was closed, but just the bracket is sometimes unclear and you have to scroll through the code and look.

A
Anton Mashletov, 2018-04-04
@mashletov

Sometimes? Lol. This is how it should always be. In general, it is better to use template engines

S
spaceatmoon, 2018-04-04
@spaceatmoon

Everything that is not forbidden will be done at some point. Plus, I suspect they don't use syntax highlighting, and many of them are parenthesized.
In the company, this is decided by the development council and the style guide is added. Do not use, for example, the ternary operator, goto, type definition only through is_*, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question