问题
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