应该省略PHP闭合标签的理由
2012年4月12日
没有评论
PHP官方文档的一段说明:
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. more>>
找了一些资料,大家对PHP闭合标签的总结如下:
好处:如果这个是一个被别人包含的程序,没有这个结束符,可以减少很多很多问题,比如说:header, setcookie, session_start这些动作之前不能有输出,如果不小心在?> 后边加了不可见字符(多余的空格、换行符)等破坏页面显示,就会报”Header already sent”错误,不写的话不会有此问题。另,可以直接把光标移到最后,接着编程。
坏处:在dreamweaver的视图模式下,一团糟。 阅读全文…