Comments in PHP

Posted by Whiz
Whether for your own benefit or for that of a programmer later tasked with maintaining your
code, the importance of thoroughly commenting your code cannot be overstated. PHP offers
several syntactical variations, each of which is introduced in this section.
Single-line C++ Syntax
Comments often require no more than a single line. Because of its brevity, there is no need to
delimit the comment’s conclusion, because the newline (\n) character fills this need quite
nicely. PHP supports C++ single-line comment syntax, which is prefaced with a double-slash (//),
like this:
// Title: My PHP program
// Author: Jason
print "This is a PHP program";
?>
Shell Syntax
PHP also supports an alternative to the C++-style single-line syntax, known as shell syntax,
which is prefaced with a hash mark (#). Revisiting the previous example:
# Title: My PHP program
# Author: Jason
print "This is a PHP program";
?>
Multiple-Line C Syntax
It’s often convenient to include somewhat more verbose functional descriptions or other
explanatory notes within code, which logically warrant numerous lines. Although you could
preface each line with C++ or shell-style delimiters, PHP also offers a multiple-line variant that
both opens and closes the comment. Consider the following multiline comment:
/*
Title: My PHP Program
Author: Jason
Date: October 10, 2005
*/
?>
Multiline commentary syntax is particularly useful when generating documentation from
code, because it offers a definitive means for distinguishing between disparate comments, a
convenience not easily possible using single-line syntax.

0 Response to 'Comments in PHP'

Post a Comment