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??
The official stance:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With