对于仅PHP文件,PHP关闭标签是否赞成的参数是什么? [英] What are the arguments IN FAVOR of PHP closing tags for PHP only files?

查看:53
本文介绍了对于仅PHP文件,PHP关闭标签是否赞成的参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Zend Framework编码标准提到以下内容:

对于仅包含PHP代码的文件,决不允许使用结束标记(?>"). PHP不需要它,并且省略它可以防止在响应中意外插入尾随空格.

但是我确实记得听说过一个问题(使用工具还是可能包括?),其中文件需要带有结束标记.

有人知道您需要关闭标签的任何问题(开发人员想要对称的问题除外)还是它们通常是个坏主意?

解决方案

在可能的情况下删除结束标记可能确实是最佳实践.这样做的原因是,如果在php文件中的?>之外有任何字符(甚至是空格),则可以在设置标头之前将字符发送到浏览器来阻止标头之类的东西停止工作.

The Zend Framework coding standard mentions the following:

For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it prevents the accidental injection of trailing whitespace into the response.

However I do remember hearing about an issue (with tooling or including maybe?) where files needed to have closing tag.

Does anyone know of any issues (other than the developer issue of wanting symmetry) where you would need to have closing tags or are they generally a bad idea?

解决方案

Removing the closing tags when you can is probably a best practice really. The reason for that is because if you have any character (even whitespace) outside of the ?> in a php file it can stop thing such as headers to stop working if the character gets sent to the browser before the header gets set.

这篇关于对于仅PHP文件,PHP关闭标签是否赞成的参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆