I didn’t know until just now that you don’t need to include the closing ?>
in PHP files that consist entirely of code. The Drupal coding standards explain why you probably want to leave it out:
Note that the final
?>
should be omitted from all code files–modules, includes, etc. The closing delimiter is optional, and removing it helps prevent unwanted white space at the end of files which can cause problems elsewhere in the system.
The most common problem it prevents is the “headers already sent” error that crops up when errant line feeds are included at the end of code files.
March 5, 2008 at 7:27 pm
I used to recommend this, but that specific justification is less of a problem now that we have the output_buffering configuration option. (Assuming you don’t disable this.)
That’s only really a worry now when you’re developing code, such as the Drupal team, where you don’t control the deployment environment.
Now I think it’s better to keep the closing ?> for all the same reasons it’s good to keep {} with if() statements, assuming you buy into those types of arguments.
March 5, 2008 at 9:11 pm
I’m definitely an always use the {} with “if” type person. However, I think that it may make sense to use this because leaving it out produces a very easy to detect bug (your page probably doesn’t compile), whereas putting it in can sometimes produce a more difficult bug to track down.