This is one of my pet peeves. Proper commenting isn't about commenting every single line or small group of lines. If you have a function that's small and well defined, put a simple set of comments at the top describing what it does in simple terms, like so:
function mt(){
// This function returns time in microseconds
$tmp = split(" ",microtime());
return $tmp[0]+$tmp[1];
}
That's all you need. Well written code should be self documenting.
If your function is large and does a lot, it's ok to put comments near the complex / inobvious parts. for instance:
function replace_first_str($break,$replace,$str){
// This function replaces the first occurance of $break with $replace, leaving the others alone.
$tmp = split($break,$str);
$str = $tmp[0].$replace;
// We're done with the $tmp[0] so we toss it away
unset($tmp[0]);
// Note the concat operator, and use of implode to reinsert the original break text.
$str.=implode($break,$tmp);
return $str;
}
Large blocks of comments should be enclosed with / / like so:
/************************
Program: yabba dabba doo
Version: 1.0
Author: Sxooter
This is the header for our program
It has the program name, version numbers,
Authors, and other important info.
It's a good idea for the lines to not be overly
wide, as it gets hard to read comments that
run off the screen in some editors.
This section should explain the overall
functioning of the program without getting
into too much detail.
***************************/
Note that there's plenty of wiggle room, and everyone has their own style. It's just important to not spend your time explaining things like:
// This is the $i for loop:
for ($i=0;$i<5;$i++){