PHP code annotation-php Tutorial

Source: Internet
Author: User
PHP code comments are written in front

Annotations can be interpreted as explanations and descriptions in the code. The use of annotations not only improves the readability of the program, but also facilitates the later maintenance of the program. The comment content is not executed by the program.

Personal Project

Personal Website: LN movie network personal blog: L & N blog

PHP comments

PHP comments have 3 styles

1. C ++ style single line comment (//)
// This is a comment: print hello worldecho 'Hello World ';
2. C ++-style multi-line comments (/**/)
/* This is a multi-line comment echo 'hao'; echo 'this world'; */echo "hello this world ";
3. use Shell-style annotations (#)

Similar to a single-line comment, # The row is not executed

Echo 'hello this world'; # shell style comment, the content here will not be executed
Valid PHP comments

Program annotation is an important part of writing standard programs. Annotations are mainly used to explain and explain the code. they are used to explain the script usage, copyright description, version number, generation date, author, and content. Help to read and understand the program

Annotation principles

Language

  • The annotation language must be accurate, easy to understand, and concise.

Note: incorrect comments are not helpful but harmful.

  • Annotations are ignored during code compilation and are not compiled into the final executable file by the compiler. Therefore, annotations do not increase the execution file size.

  • Annotations can be written anywhere in the code, but are generally written at the beginning or end of the code.

Note: Avoid inserting comments in a line of code or expression. Otherwise, comprehension deviations may occur.

  • When modifying the program code, you must modify the relevant comments at the same time to ensure that the code and comments are synchronized.

  • In actual code specifications, it is required that the proportion of comments to program code should be about 20%, that is, 20 comments to 100 lines of code

Note: avoid unnecessary comments

  • Add comments to the right of the end line of the block to indicate that a program is about to end.

  • Avoid using abbreviations in comments.

  • Comments are the same abbreviations as the descriptions, so that the program can be neatly formatted and easy to read and understand.

Summary

If we want to be a rigorous and attitude programmer, these seemingly insignificant principles actually represent a kind of responsible attitude towards the program we write.

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.