Shell-style comments in php

When PHP encounters a hash mark character (#) within the code, everything from the hash mark to the end of the line or the end of the section of PHP code (whichever comes first) is considered a comment. This method of commenting is found in Unix shell scripting languages and is useful for annotating single lines of code or making short notes.

Because the hash mark is visible on the page, shell-style comments are sometimes used to mark off blocks of code:

#######################
## Cookie functions
#######################

Sometimes they’re used before a line of code to identify what that code does, in which case they’re usually indented to the same level as the code:

if ($doubleCheck) {
 # create an HTML form requesting that the user confirm the action
echo confirmationForm();
}

Short comments on a single line of code are often put on the same line as the code:

$value = $p * exp($r * $t); # calculate compounded interest

When you’re tightly mixing HTML and PHP code, it can be useful to have the closing PHP tag terminate the comment:

<?php $d = 4; # Set $d to 4. ?> Then another <?php echo $d; ?>
Then another 4

Leave a Comment