Skipping PHP end tag [duplicate]

非 Y 不嫁゛ 提交于 2019-12-03 12:52:17

The official stance:

Note: The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

It's useful when creating class files / code files, as it's very easy to add an extra space or newline at the end of a file, which can mess up output buffering header() output. Since PHP treats an EOF like a closing ?> in a file there's no danger in relying on the EOF.

Yes, it's useful, because you can't forget odd chars like \n after closing tag (which can prevent from sending cookies etc). In Zend Framework they do not use closing tags also (as a project code standart).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!