PHP Syntax: Three Ways to Create Comments
PHP allows three different methods of formatting comments. All of these sytax examples will seem familiar to programmers of other languages.
Few things in programming stimulate as much conflict as commenting. Many code gods can just read the code like most of us read the newspaper. For these coding savants, commenting is seen as a frivolous waste of time.
However, for code monkeys like myself who can barely keep track of what was going on 5 minutes ago, it makes a lot of sense to me that code be heavily commented. Trying to struggle through poorly commented code is a torture.
Whatever your feelings on commenting, you will need to know the three different methods used to create comments within PHP code.
Slash-asterisk pairs are used to surround a multi-line comment block.
/* This is an example of slash-asterisk pairs being used to create a comment block. This comment block can be as long as required. This method is frequently used to "comment out" large blocks of code in testing. */
The double slash (//) and pound sign (#) are the two methods used to create inline comments. Everything following either of these will be ignored and will be considered a comment.
$var++; // anything to the right of the double slash will be ignored
$var=2; # right of the pound sign is considered a comment
View more articles by David Kirk
Follow the reactions below and share your own thoughts.