Comments refers to the process of programming, the program files or code snippets added an additional note. Annotating can improve code readability, allowing yourself or other developers to understand the program more quickly.
Notes in the programming process is very important, the appropriate commentary program is not only the programmer's personal habits, but also the responsibility of expression. But in the actual process, most programmers do not have a good habit of annotating the program, which often in the future for themselves or others cause considerable trouble.
PHP comments are not part of a PHP program and their contents are not part of any function calculations in the program and are displayed in special colors (such as green) in the editor.
PHP comment symbol
PHP supports C ++, C, and Unix shell style (Perl style) annotations, so there are three kinds of PHP comment symbols:
- C++ style: // This is a C + style annotation
- C style: /* This is a C-style comment */
- Unix Shell style: # This is a Unix shell style comment
PHP comment format
PHP comment format is divided into single-line comments and multi-line comments.
PHP single-line comment
The above three symbols can be used for single-line comments, except that when you use the // or # comment, the text following the comment symbol (within the line) is treated as a comment, and the /* */style comment must end with */.
<?php // This is a single line comment echo 'Hello! '; // This is a single-line comment, written after a line of code, also called line-end comments /* This comment style is also good */ # Less used style ?>
The end-of-line comments above are usually just comments on the front of the line. A single-line comment might be an annotation to one or more lines of code below, or it may be for the overall look and feel of the program.
PHP multi-line comments
Multi-line comments generally use C-style comments, beginning with /* and ending with multiple lines.
<?php Hello " Hello! "; /* This is a multiline comment This is inside the Notes content More annotation content and so on */ ?>Note
Do not nest C-style comments, because the first */when the system that is the end of the Notes, in a large chunk of code when the comment is very prone to the error. A PHP syntax error is generated as follows:
<?php echo 'Hello! '; /* This is a multiline comment echo 'output some other content'; /* add the line comment */ */ ?>
You can also use the // symbol multiple times to comment on multiple lines of code, but are generally limited to a limited number of lines:
<?php // Pagination display customization // upPage: Previous page // downPage: Next page protected $config = array ( 'Header' =>'record', 'Prev' =>'Previous', 'Next' =>'Next', ); ?>
PHP comments can not contain PHP code at the end of the ?>