Luke Luke - 3 months ago 7
PHP Question

Closing PHP tags after exit or die functions

Should I close PHP tags after

die
or
exit
functions or it is not necessary?

Answer

According to the docs, only omit the closing tag if it's at the end of the file:

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

-- http://php.net/manual/en/language.basic-syntax.phptags.php

This applies to exit and die calls as well. They would run through the same parser as the rest of your php code.

Comments