Why would one omit the close tag?

前端 未结 14 1547
旧巷少年郎
旧巷少年郎 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:11

    According to the docs, it's preferable to omit the closing tag if it's at the end of the file for the following reason:

    If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

    PHP Manual > Language Reference > Basic syntax > PHP tags

提交回复
热议问题