Hi,
While I was developing with Magento, I found out that I don't need to put php end tag (?>) if I don't use HTML below PHP code. Is it safe and why don't we just put end tag?? Is it useful??
Hi,
While I was developing with Magento, I found out that I don't need to put php end tag (?>) if I don't use HTML below PHP code. Is it safe and why don't we just put end tag?? Is it useful??
Yes, it's useful, because you can't forget odd chars like \n after closing tag (which can prevent from sending cookies etc). In Zend Framework they do not use closing tags also (as a project code standart).
Note: 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.
It's useful when creating class files / code files, as it's very easy to add an extra space or newline at the end of a file, which can mess up output buffering header()
output. Since PHP treats an EOF like a closing ?>
in a file there's no danger in relying on the EOF.