Working on my Raspberry Pi LAMP and WordPress install, I just so happened to notice that the wp-config.php file didn’t include the closing php tag ?> and was curious why.
When you are distributing files and can expect users to be using dodgy editors that add extra lines or erroneous spaces on the end of files….. and such…..
It’s quite easy for extra spaces to end up on the end of a file, and if you’re using several includes tracking these spaces down can be a pain, especially if you’re dealing with lots of files… spaces after closing PHP tags is known to cause various issues including invalid headers…
Of course there are cases when not using closing tags causes problems to, so it’s catch 22…
From the PHP documentation:
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.