tags:

views:

147

answers:

3

in some scripts I see that they omit writing a closing tag ?> for the script .. I don't know why .. Can someone tell me why and if I should do this as well.

(I'm sure they have not forgotten it ;) , lol )

edit: thank you guys :) , I got it now

+1  A: 

They do it to avoid risking to have whitespaces after the closing tag which may stop headers to work.

This is, of course, true for PHP-only files.

Soufiane Hassou
+10  A: 

Well, omitting the closing tag is just one solution for avoiding blanks and other characters at the end of file. For example any char which is accidentally added behind the closing tag would trigger an error when trying to modify header info later.

Removing the closing tag is kind of "good practice" referring to many coding guidelines.

dhh
Some would also consider this to be a language defect.
D.Shawley
In some cases isn't it what is required? People are responsible for cleaning up the whitespaces after the ending tag. In some cases someone might require the output after the ending tag.
Kieran Allen
+3  A: 

From PHP: Instruction Separation

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

Metalshark