Value of omitting ?> in PHP only files

Asked by At

Possible Duplicate:
PHP closing tag

I've read recently that the ?> should be omitted from files that contain ONLY PHP

In fact even the Zend Framework code standard strongly discourages using ?> in files containing only PHP because:

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 white space into the response.

Is the injection of trailing white space really that bad? And it is really a hideous crime to not omit the ?> from files containing only PHP? It simply seems unnatural for me to do so.

3 Answers

Quentin On Best Solutions

If you inject white space in an include and then try to use header() (or something else that depends on running before content is output) then you'll be entering debug hell. This is a quick and easy technique for avoiding that.

Vytautas On

If accidental injection happens you cannot send header or start session but errors will show you that. If that happens on every file you have then you have some problems

JKirchartz On

As far as I know there are no code police running around chopping off people's hands for doing something like this. I say write good code and leave the ?> in.