Closing PHP tag considered harmful

A good tip from Zend, who recommend omitting the closing PHP tag (?>) when your files contain pure PHP code. This can prevent additional whitespace being inserted into the script output. Extra whitespace can cause problems, for example, if you are trying to set your own custom HTTP headers: nothing should be output before the call to the header function. Otherwise, this classic error will occur:


Cannot modify header information - headers already sent by (output started at myinclude.php:16) in myscript.php on line 15

Zend Framework: Documentation

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.