Home  >  Article  >  Backend Development  >  The benefits of not writing closing tags in php_PHP tutorial

The benefits of not writing closing tags in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:37:06911browse

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:

Copy code The code is as follows:

echo "Here's my code!";
?>

Appropriate:
Copy code The code is as follows:
echo "Here's my code!";
/* End of file myfile.php */
/* Location: ./system/modules/mymodule/myfile.php */

Therefore, if it is a pure php code file, the ?> closing identifier should be omitted.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736809.htmlTechArticleI first came into contact with this concept from Drupal. 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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:A concise tutorial on using ThinkPHP verification code_PHP tutorialNext article:A concise tutorial on using ThinkPHP verification code_PHP tutorial

Related articles

See more