PHP files just start the tag and not the end tag?

Source: Internet
Author: User
Tags closing tag
Project to be useful to the PHP yii framework, today read the canonical document
Https://github.com/yiisoft/yii/wiki/Core-framework-code-style

Inside it says: Php file just start tag 不要结束标签 ?>, 印象中好像有看到其他框架也这么说过, 貌似会更安全, 为什么, 哪里有相关介绍?

Reply content:

Project to be useful to the PHP yii framework, today read the canonical document
Https://github.com/yiisoft/yii/wiki/Core-framework-code-style

Inside it says: Php file just start tag 不要结束标签 ?>, 印象中好像有看到其他框架也这么说过, 貌似会更安全, 为什么, 哪里有相关介绍?

This is the recommended usage in the official manual, which is described in detail in the manual:

If the file content is pure PHP code, it is best to remove the PHP end tag at the end of the file. This avoids having to accidentally add a space or line break after the PHP end tag, which causes PHP to start outputting these blanks, and there is no intention to output the script at this time.

Plain PHP files must omit the close tag,
A blank line must be at the end of the file.
Change as if it had to be LF.

This is the PSR-2 style guide, a guide that has been summed up after many open-source project style surveys, a method that most people use. Designed to switch between different PHP projects, or to review other people's code, can start seamlessly, reducing the cost of familiar styles. This style of all content is meaningful, such as omitting the close tag is mainly the file include and output content is not disturbed by the consideration. Otherwise, it is very likely that after your closing tag is doped into another file, inexperienced people will find it difficult to troubleshoot errors.

www.php-fig.org

I translate this two days, yii2 style, basically on the basis of PSR2 to make a few changes (indent four spaces to tab), https://github.com/AbrahamGreyson/yii2-zh-cn/blob/master/ Internals/core-code-style.md

Corrected, after intense discussion, Yii2 decided to fully compatible with PSR2, removing the tab indent and changing to a 4-space indent that better fits most of the community's habits.

A little off-topic, this is just a code style guide, the biggest meaning is not everyone to abide by it, but in a circle as far as possible to maintain consistency, in order to improve the efficiency of collaboration, at this point, Google has an article dedicated to the company's internal code specification of the need. We support and respect the basis of the guide is that, not so much personalization, everything in accordance with the custom of the Convention. There are quite a few major projects in PHP that are in full compliance with this style. For example Yii2 Symfony2 laravel. If you want to test the integration of style checks, you can install Php_codesniffer, he can be built when you check whether the style is in line with your settings.

Another comment is another category, and it is recommended that you use annotations that conform to the PHPDOC specification. You can automatically generate API manuals for your code, instead of class diagrams such as UML. Quick Query is convenient.

If you use a closed tag, any space behind a closed tag by a developer, user, or FTP application can cause extra output, PHP errors, output that cannot be displayed, and blank pages. Therefore, all PHP files should omit this PHP closed tag, and insert a note to indicate that this is the file's bottom and locate the file in the relative path of the application. This will help you to make sure that the document is over and not truncated.

Excerpt from CI Handbook

I have eaten a loss yesterday. When the file is require, it will send the superfluous things over.

  • 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: info-contact@alibabacloud.com 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.