Does the php file only need to start the tag instead of end the tag? -Php Tutorial

Source: Internet
Author: User
Tags api manual
The phpyii framework is used in the project. today, I read the standard documentation github. comyiisoftyiiwikiCore-framework-code-style, which says: The php file only needs to start the label & amp; lt ;? Php do not end the tag? & Amp; gt; It seems that other frameworks have also said this... the php yii Framework is used in the project. today I have read the standard documentation.
Https://github.com/yiisoft/yii/wiki/Core-framework-code-style

It says: The php file only needs to start the label. Do not end the tag?>It seems that other frameworks have said this, and it seems to be safer. why?

Reply content:

The php yii Framework is used in the project. I read the standard documentation today.
Https://github.com/yiisoft/yii/wiki/Core-framework-code-style

It says: The php file only needs to start the label. Do not end the tag?>It seems that other frameworks have said this, and it seems to be safer. why?

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

If the file content is pure PHP code, it is best to delete the PHP end mark at the end of the file. This avoids accidental addition of spaces or line breaks after the PHP end mark, which may cause PHP to start to output these spaces, but the script does not have the intention to output at this time.

The close tag,
A row must be empty at the end of the file.
The change seems to be LF.

This is in the PSR-2 style guide, which is a method that most people use after many open source project style surveys. It is designed to seamlessly start switching between different PHP projects or reviewing others' code, reducing the cost of familiarization. All the content in this style is of some significance. for example, omitting and disabling tags is mainly a consideration of file include and output content without interference. Otherwise, it is very likely that something will be added to another file after your tag is closed, and it is difficult for inexperienced people to troubleshoot the error.

Www.php-fig.org

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

After heated discussion, yii2 decided to be fully compatible with psr2, removed tab indentation, and changed it to a four-space indent that better fits the habits of most people in the community.

Aside from a single question, this is just a code style guide. The biggest significance is not that everyone complies with it, but that everyone tries to maintain consistency in a circle to improve collaboration efficiency, at this point, google has an article dedicated to the necessity of the company's internal code specifications. The Foundation for everyone's support and respect for this guide is that, without so much personalization, everything follows the conventions of everyone. At present, PHP has quite a large number of projects in full compliance with this style. For example, yii2 symfony2 laravel. If you want to check the integration style during the test, you can install PHP_CodeSniffer, which can check whether the style meets your settings during the build.

In addition, annotations are another category. we recommend that you use annotations that comply with the PHPdoc specifications. You can automatically generate your code into an api manual, instead of class diagrams such as uml. Quick query is convenient.

If you use closed tags, any developer, user, or the spaces after inserting the closed tag in the FTP application may cause redundant output, php errors, and subsequent output failures or blank pages. Therefore, all php files should omit this php closed tag and insert a comment 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 determine that the file has been ended rather than deleted.

From CI manual

I have suffered a loss yesterday. When the file is require, it will send out unnecessary items.

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.