PHP Alternative management structures, any flaws?

I worked with code PHPthat generates HTML without any templates, and it's pretty spaghetti and hard to read the way they structured it. One of the ways I have dramatically improved after the stream, which I noticed, is to use : endifinstead of blocks { }in some cases to increase readability. (See http://php.net/manual/en/control-structures.alternative-syntax.php )

  • Is it portable?
  • This standard?
  • Is this slower in any significant way (I understand that it takes more characters)

Hooray!

+3
source share
5 answers

?

?

- ( , )

.

imho , HTML.

:

<?php foreach($array as $value): ?>
    <div>
    <?php if($value == "foo"): ?>
        <p><?php echo $value; ?></p>
    <?php endif; ?>
    </div>
<?php endforeach; ?>

<?php foreach($array as $value) { ?>
    <div>
    <?php if($value == "foo") { ?>
        <p><?php echo $value; ?></p>
    <?php } ?>
    </div>
<?php } ?>

, , endif endforeach <?php } ?>. , HTML!

, "" .

+7

, . , , .

, , , ( ).

. . , } //end of while, .

+4

PHP, ?

, % vim . .

+1

: , , . . , , .

Personally, I, being trained and using c-style languages, my whole programming career (so far), I prefer curly braces with a simple comment after the curly brace ends, which tells you that it ends.

0
source

The only drawback that I see is that in an editor, such as sublime text, there are options such as "Switch to a consistent bracket" and "Expand selection in brackets" that will not work with alternative syntax

0
source

Source: https://habr.com/ru/post/1757399/


All Articles