Why would one omit the close tag?

前端 未结 14 1577
旧巷少年郎
旧巷少年郎 2020-11-21 06:18

I keep reading it is poor practice to use the PHP close tag ?> at the end of the file. The header problem seems irrelevant in the following context (and this

14条回答
  •  长发绾君心
    2020-11-21 07:18

    The reason you should leave off the php closing tag (?>) is so that the programmer doesn't accidentally send extra newline chars.

    The reason you shouldn't leave off the php closing tag is because it causes an imbalance in the php tags and any programmer with half a mind can remember to not add extra white-space.

    So for your question:

    Is there another good reason to skip the ending php tag?

    No, there isn't another good reason to skip the ending php tags.

    I will finish with some arguments for not bothering with the closing tag:

    1. People are always able to make mistakes, no matter how smart they are. Adhering to a practice that reduces the number of possible mistakes is (IMHO) a good idea.

    2. PHP is not XML. PHP doesn't need to adhere to XMLs strict standards to be well written and functional. If a missing closing tag annoys you, you're allowed to use a closing tag, it's not a set-in-stone rule one way or the other.

提交回复
热议问题