Comments
Comments are pieces of code that the PHP parser skips. When the parser spots a comment, it simply keeps going until the end of the comment without doing anything. PHP offers both one line and multi-line comments.
One-Line Comments
One-line comments are comments that start where ever you start them and end at the end of the line. With PHP, you can use both // and # for your one-line comments (# is not commonly used). Those are used mainly to tell the reader what you're doing the next few lines. For example:
//Print the variable $message
echo $message;
It's important to understand that a one-line comment doesn't have to 'black out' the whole line, it starts where ever you start it. So it can also be used to tell the reader what a certain variable does:
$message = ""; //This sets the variable $message to an empty string
The $message = ""; is executed, but the rest of the line is not.
Multi-Line Comments
This kind of comment can go over as many lines as you'd like, and can be used to state what a function or a class does, or just to contain comments too big for one line. To mark the beginning of a multiline comment, use /* and to end it, use */ . For example:
/* This is a
multiline comment
And it will close
When I tell it to.
*/
You can also use this style of comment to skip over part of a line. For example:
$message = ""/*this would not be executed*/;
Although it is recommended that one does not use this coding style, as it can be confusing.
All text is available under the terms of the GNU Free Documentation License
Source : Wikibooks
|