As a sign to all of the followers of the Sugar Developer Blog that we don’t just ignore the comments made to posts, I thought I would pull out a comment from my previous blog post to comment on. Here it is:
Hi John,
thanks for all. Can i ask something ? Why you don’t close de php tag ?
Is there any tip who can help for when use a close tag and where not ?
This is a pretty valid question, and probably one that is a bit confusing for those new to PHP. Let me explain…
As many of you know, PHP roots come from it being a language that was designed to be embedded within HTML markup, thus the need for tags in the first place to surround the PHP code that may be embedded within an HTML script. Nowadays, most PHP code written is kept separated from the presentation HTML markup, so files don’t necessarily need to jump back and forth between PHP and HTML. For these PHP only files you still do need an opening tag at the very beginning of the file, but you don’t need a closing tag since the EOF character is an implicit one effectively. Doing so has other benefits other than just saving a few extra characters, as pointed out in the Zend Framework Programmer’s Reference Guide:
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.
So leaving out the closing tag eliminates trailing whitespace, which can throw off AJAX responses and various other scripts in the application. You do of course need the closing tag whenever you are mixing HTML and PHP code still, but otherwise it’s generally considered best practice to leave it out, and we try to follow this practice in SugarCRM.
{ 0 comments }