PSR-2 coding standard: why no closing PHP tag in files containing only PHP? [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-11 12:41:45

问题


I just heard of the PSR-2 coding standard in a comment on this question: Is there any reason to use the "public" keyword before method and member variable names?

I have a question on one of the rules in the PSR-2 standard:

The closing ?> tag MUST be omitted from files containing only PHP.

What is the point of that?


回答1:


It is a good universal rule not using closing tag in php scripts. Note that everything after that closing tag is sent to client (browser) even white characters so if you're using closing tag and new line or any other white character it will be sent to browser. In most cases this behavior is not desirable.




回答2:


There where you read about PSR should be explanation like this: Because you may get problems with additional (unexpected) white spaces after the closing ?> tag - they will go to the output.




回答3:


To prevent issues from trailing whitespace http://hardcorewp.com/2013/always-omit-closing-php-tags-in-wordpress-plugins/



来源:https://stackoverflow.com/questions/24212806/psr-2-coding-standard-why-no-closing-php-tag-in-files-containing-only-php

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