Why I don’t use closing PHP tags

Never use closing tags in PHP, they add unnecessary whitespace which could seriously mess up your website or application. Plus they’re not required.

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 :


Author: Luc De Brouwer

Luc is a web developer who loves WordPress, Magento, PHP, MySQL, HTML, CSS, jQuery, good food and Nine Inch Nails.

5 thoughts on “Why I don’t use closing PHP tags”

Fatal error: Call to undefined function the_comments_navigation() in /var/www/vhosts/thepersistenceofloss.com/httpdocs/wp-content/themes/twentysixteen/comments.php on line 49