PHP Comments

If the urge ever hits to write something down in the middle of a block of PHP code, you can do this one of two ways.

1. You can type in your comment and move on, causing errors in your program.
2. You can label your comment as a comment and move on without causing errors (assuming, of course, that all of the other code is correct).

Hopefully you will choose the second option, in which case you once again have two options.

1. You can comment out a single line of code.
2. You can comment out a large block of code.

Comments are most often used for two purposes:

1. To note what is happening at certain points throughout a block of code. (You will probably be thankful for properly used comments years later when you return to your own long-untouched code, or try to understand another programmer's code!)

2. To temporarily keep a line or multiple lines of code from being interpreted, without deleting it completely (a useful option during testing).

Comments are never seen by anyone who cannot see the php code. Three different methods can be used to create comments:



/*   */

They can be used in the following manners:

  // This comment only spans one line.
  // It can, however, be used on as many lines as necessary.

  # This comment only spans one line.
  # It is not used as commonly as the previous type.

  /* This comment can span one line. */

  /* This comment can also span as many lines as needed.
     It is useful when commenting out large chunks of code at a time.
     This type of comment cannot be nested, or errors will occur.