PHP does not write the benefits of closing tags

Source: Internet
Author: User
Tags closing tag php code zend

When I started writing PHP code, I was going to write PHP closed tags, after a few years, habits changed, no longer write PHP tags.

The concept was first approached from Drupal, and at first it was a bit of a habit-why not write a closed tag? This feeling is not perfect, for people with obsessive-compulsive disorder is very not adapt to it! Later, in the work encountered because of the closure of the problem caused by the label, began not to write closed tags.

See a few articles, the summary of the PHP closed tag is as follows:

Benefits: If this is a program that is included by others, without this terminator, you can reduce a lot of problems, such as: header, Setcookie, session_start These actions can not have output before, if you accidentally add an invisible character behind?> (extra space , line breaks, and so on, will be reported "Header already sent" error, do not write words will not have this problem. Alternatively, you can move the cursor directly to the end and then program.

Cons: In the Dreamweaver view mode, a mess.

The official explanation for the PHP closed tag is that the PHP closed tag "?>" is optional for PHP parsers in PHP. However, if you use a closed tag, any space that is inserted by the developer, user, or FTP application after the closing tag may cause excess output, PHP errors, subsequent output that cannot be displayed, and blank pages. Therefore, all PHP files should omit this PHP closing tag and insert a note to indicate that this is the bottom of the file and locate the relative path of the file in this application. This will help you to make sure that the document is over and not truncated.

This is also mentioned in the Code specification for Zend:

code example: Improper:     code is as follows: <?php echo "Here's my code!"; ?> appropriate:   Code as follows: <?php 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, you should omit the?> ending identity Character.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.