We often see that some PHP files in the code is only the start tag, and there is no end tag, then under what circumstances can not write this end tag, and under what circumstances must write? Let's take a look at 2 examples:
The following code works correctly:
<? PHP echo 123456;
The following code is an error:
<? PHP echo 123456; <p>abc</p>
Cause Analysis:
The former is pure PHP code, you can not write the end tag, and do not recommend to write the end tag, the latter in addition to PHP code, and HTML code, you must write the end tag.
Why is it not recommended that the former write the end tag?
When you do not write the PHP end tag, the default from the start tag is the PHP code, if there are other code, it will be an error. PHP can only run the script inside the PHP tag, all characters outside the script, including the space you can't see or the carriage return, the tab symbol, will be response to the client as the output, which may produce unexpected things. For example, the file is used in the header function, the file also contains another file, and the file contained in the PHP tag has null characters, this time will be reported to the header already send error. We look at some of the Web page source code to see the beginning of a lot of space and newline, that is because of this cause.
Solution Recommendations:
library files, or some class files, and so on only pure PHP code files are not recommended to add the end tag.
Under what circumstances can not write PHP end tag "?>"