All About Commenting
By admin • May 2nd, 2008 • Category: 1.2. Code Basicstest test estset
testsetset
test
It can be confusing when you start developing in a new language to know about the rules for commenting. For example when I started coding in VB.NET, I was shocked to find no way of bulk commenting out code. Every line needed to be commented out. Crazy stuff.
Luckily for us, we’re working with PHP, and PHP has been developed with bulk commenting options, which I find to be very handy, especially when debugging.
Single Line Commenting
To my knowledge, there are two ways of doing single line comments in PHP. The first is with two forward slashes as follows:
<?php // echo 'this is text that is going to be commented out'; ?>
The second, which is fast becoming my preference, is a single hash character, as follows (I prefer this because I find it faster to type, you will have to find your preference):
<?php # echo 'this is text that is going to be commented out'; ?>
Multiple Line (Bulk) Commenting
Single line commenting is all well and good, but there are times when bulk commenting can be very useful too. I find bulk commenting to be useful in two situations:
1. When providing summary text to functions or classes
I find this looks neater than a bunch of single line comments. Again, just my preference.
<?php
/*
Author: Me
Summary: This function does some really cool stuff.
To use this function, do this, this and this.
Parameter var1: An integer
*/
function do_something($var1){
//do stuff in here
}
?>
2. When debugging code
When I need to find the source of an error in my code, I’ll use bulk commenting to hide sections of code, until I’ve found where my error is happening. Very useful ![]()
admin is
Email this author | All posts by admin
