I first came across this concept from Drupal, and I was a little uncomfortable at first - why not write a closing tag? This feels very imperfect, and very uncomfortable for people with obsessive-compulsive disorder! Later, I encountered problems caused by closing tags at work, so I started not writing closed tags.
After reading some articles, the summary of PHP closing tags is as follows:
Benefits: If this is a program included by others, without this terminator, many, many problems can be reduced, such as :header, setcookie, session_start cannot have output before these actions. If you accidentally add invisible characters (extra spaces, newlines) after ?> to damage the page display, a "Header already sent" error will be reported. No If you write, you won't have this problem. In addition, you can directly move the cursor to the end and continue programming.
Disadvantages: In Dreamweaver’s view mode, it’s a mess.
The official explanation about the PHP closing tag is: The PHP closing tag "?>" is optional for the PHP analyzer in PHP. However, if a closing tag is used, any space inserted after the closing tag by a developer, user, or FTP application may cause redundant output, PHP errors, subsequent output that cannot be displayed, and a blank page. Therefore, all PHP files should omit the PHP closing tag and insert a comment to indicate that this is the bottom of the file and locate the file relative to the application. This will help you make sure that the file has ended and not been deleted.
This is also mentioned in Zend's code specification: http://framework.zend.com/manual/1.12/en/coding-standard.php-file-formatting.html
Code Example:
Inappropriate:
Therefore, if it is a pure php code file, the ?> closing identifier should be omitted.