I got a question by a fellow programmer last tuesday about why I don’t use closing PHP tags. First of all, PHP doesn’t require it, so you even save a few bits on your total filesize. But the most important reason is that it prevents additional whitespace that could really mess up your website or application.
Many years ago during the whole pageflip hype I was asked by a client to develop a Flash pageflip using frequently changing input for their catalog. I couldn’t convince him to present his catalog in a more web-friendly manner so I knuckled down. I decided to dynamically generate images based on the client’s content coming from a database. After I made a working proof-of-concept a colleague was asked to do some alterations and soon after I got a phone call. The pageflip didn’t work anymore. It turns out my colleague had added closing PHP tags and a newline in the file for the image creation resulting in a damaged image.
So remember, never ever add closing PHP tags if you don’t need to.
P.S.: The tag I’m talking about obviously is :
?>
The PHP manual has the following to say about this:
Perhaps this reference to the official PHP website will help while explaining it to your colleagues.
True, but telling people to RTFM usually means they won’t..
Adding what damage it might cause would be helpful.
It would solve one of the most common errors, that is header() errors.
I did, in my case the extra ( unnecessary ) whitespace broke my images ( or at least the output of them ).