I keep reading it is poor practice to use the PHP close tag ?>
at the end of the file. The header problem seems irrelevant in the following context (and this
As my question was marked as duplicate of this one, I think it's O.K. to post why NOT omitting closing tag ?>
can be for some reasons desired.
) PHP source is valid SGML document, which can be parsed and processed without problems with SGML parser. With additional restrictions it can be valid XML/XHTML as well. Nothing prevents you from writing valid XML/HTML/SGML code. PHP documentation is aware of this. Excerpt:
Note: Also note that if you are embedding PHP within XML or XHTML you will need to use the < ?php ?> tags to remain compliant with standards.
Of course PHP syntax is not strict SGML/XML/HTML and you create a document, which is not SGML/XML/HTML, just like you can turn HTML into XHTML to be XML compliant or not.
At some point you may want to concatenate sources. This will be not as easy as simply doing cat source1.php source2.php
if you have inconsistency introduced by omitting closing ?>
tags.
Without ?>
it's harder to tell if document was left in PHP escape mode or PHP ignore mode (PI tag may have been opened or not). Life is easier if you consistently leave your documents in PHP ignore mode. It's just like work with well formatted HTML documents compared to documents with unclosed, badly nested tags etc.
It seems that some editors like Dreamweaver may have problems with PI left open [1].