Home > Article > Backend Development > What are the benefits of not writing ?> at the end of the php file?
I have seen that it is not included in many php files before PHP's terminator, I saw a demo today, which just explained the benefits of not using the ?> terminator. The following is a screenshot of a.php: Pay attention to the fourth and fifth lines)
Run the second file and you will find that it will throw a warning Say header already sent out The main reason is that there are a few blank lines in a.php after the PHP terminator is called, so PHP will think it is html code. In this case, there will already be header output before session_start is called. Before calling session_start, there cannot be any output, so the program will throw a warning. If you use ?>, you may make this mistake inadvertently. When the project is large and the amount of code is large, it is difficult to find such a problem. Therefore, it is best not to write ?> at the end of the PHP file. This is the officially recommended approach by zend. |