Visit the Official PHP Website

Search this Site

PHP Programming

By James N Hitz

PHP Comments for Real

There are three types of comments supported in PHP:

  1. C style //comment here
  2. C++ style /* comment span */
  3. Unix-style #

Any text preceded by two fore-slashes is ignored - only up to the end of that line. This is the style of commenting used in the C programming language hence the term C-style comments:

//this is a comment
$variable = "value"; //comment starts halfway till the end.

The Unix-style of commenting works exactly like the C-style comment, only the symbol used is different. A hash symbol (#) is used:

	#this is a comment
	$variable="value"; #comment starts halfway

To have a comment spanning multiple lines, like in the C++ style of commenting, enclose it within a slash-star /* and a star-slash */;

/* a comment spanning more than one lines can also be used
   and is good for explaining the complex details in your code*/

Avoid nesting comments - especially the C++ style of comments:

/* a comment /* contained in another */ may present problems */

Avoid over-commenting your code. This makes the script files un-necessarily large and thus delays loading and execution. If anything it makes the code look cumbersome.

<< Into Lesson 8 | File Management >>

JamHitz Productions