Searching...
Tuesday 11 June 2013

PHP Basics - Part 2 :: Commenting PHP Code

php comment syntax

Because documentation is such an important part of effective code creation and management, considerable effort has been put into devising solutions for helping developers automate the process. Used to document all code within an application, including scripts, classes, functions, variables, and more, Doc-blocks (comments block) contain human-readable explanations along with formalized descriptors such as the author’s name, code version, copyright statement, function return values, and much more.
Even if you’re a novice programmer, it’s strongly suggested you become familiar with advanced documentation solutions and get into the habit of using them for even basic applications. Whether for your own benefit or for that of somebody tasked with maintaining your code, the importance of thoroughly commenting your code cannot be overstated.

PHP offers several syntactical variations for commenting in your PHP program.

Single-Line C++ Syntax

PHP supports C++ single-line comment syntax, which is prefaced with a double slash (//), like this:

<?php
// Title: My first PHP script
// Author: Jason Gilmore
echo "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 (#), like this:

<?php
# Title: My first PHP script
# Author: Jason Gilmore
echo "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 warrants numerous lines. Although you could preface each line with C++ or shell-style delimiters, PHP also offers a multiple-line variant that can open and close the comment on different lines. Here’s an example:

<?php
/*
Processes PayPal payments
This script is responsible for processing the customer's payment via PayPal.
accepting the customer's
credit card information and billing address.
Copyright 2010 W.J. Gilmore, LLC.
*/
?>
At the end of this very short introduction to php i can only tell you to choose the way of commenting you wan't. 

0 comments:

Post a Comment

 
Back to top!