should I put a semi-colon after a single PHP statement?

后端 未结 5 679
南笙
南笙 2021-01-07 20:13

e.g.

some html....

more html...

?

相关标签:
5条回答
  • 2021-01-07 20:40

    It might be better to always use a semi-colon :

    • Lowers the probability of errors if you need to extend your code in the specific section.
    • Improves readability of code
    0 讨论(0)
  • 2021-01-07 20:41

    It's really up to you. I do, as it helps me with code readability.

    0 讨论(0)
  • 2021-01-07 20:44

    I'd recommend it, if for no other reason than it's a good habit to get into, like properly indenting html.

    0 讨论(0)
  • 2021-01-07 20:57

    I find that not doing so can:

    1. Break syntax highlighting in some editors / IDE (not critical, but annoying)
    2. Make code harder to maintain.

    So yes, I recommend doing so, unless you are sure short tags are fine for the server config in which case its not really relevant.

    When editing other people's stuff, I try to just follow the same style.

    0 讨论(0)
  • 2021-01-07 21:00

    This particular little idiosyncrasy is discussed in the instruction separation manual page.

    The bottom line is that it's not enforced either way, so it's left up to the programmer. It's a decent item to touch on in any sort of PHP coding standard, but as far as standards go, it's a relatively minor issue.

    Personally, I have started always using a trailing semi-colon. It's easier on your IDE, and helps avoid those quick little parse errors when you jump into a template and start appending code (especially in a verbose template, that might not have user-friendly line wrapping).

    0 讨论(0)
提交回复
热议问题