About PHP closing tag “?>”

Just my two cents about this debate. To summarize :

Always keep the closing PHP tag “?>” for files containing only PHP ?

Pros

Cons

  • Avoids headache with adding inadvertently whitespaces after the closing tag, because it breaks the header() function behavior… Some editors or FTP clients / servers are also known to change automatically the end of files (at least, it’s their default configuration)
  • PHP manual says closing tag is optional, and Zend even forbids it.

Conclusion

I would say that the arguments in favor of omitting the tag look stronger (helps to avoid big headache with header() + it’s PHP/Zend “recommendation”). I admit that this isn’t the most “beautiful” solution in terms of syntax consistency, but I can’t find anything better.

Advertisements