I have recently seen code samples of php which looks something like this:
<?php
//some code here
//some more code
Is it possible to write a php code without closing tags? thanks in advance.
I have recently seen code samples of php which looks something like this:
<?php
//some code here
//some more code
Is it possible to write a php code without closing tags? thanks in advance.
This is from PHP Manual
"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."
Yeah. In fact it's recommended to do that. IDE softwares like, PhpStorm, for example, are marking it as warning recommending to you to remove the PHP closing tag.
Explanation:
It's unnecessary.
It's easy to accidentally add significant whitespace after the ?>
, which will be output to the client, which in turn can lead to obscure 'headers already sent' errors (this happens when an included file contains whitespace, and you try to set a header after including that file).
I think this question was answered before here:
Why would one omit the close tag?