Learning PHP Part 10 : Ways of writing comments in PHP code


Learn PHP tutorials at this time we will discuss the ways of writing comments in PHP code. PHP provides several ways to add a comment that is similar to the way commenting in other programming languages such as C, C++ and Unix Shell.

Comments on the need to give an explanation to others who read our code. Comments fully will be ignored by PHP at the moment of execution. Even though you think that maybe only you will read the code of the program, but it is a good idea. I myself often confused while understanding some line of code program after several months did not see it.

Good comments are comments short and not too long, but it gives an explanation of the usefulness of the code or the variables are created.

In addition as a place to make an explanation, the nature of the comment will not be executed by PHP, gives another advantage in the manufacturing process of the program. I often make a few lines of code as a comment when searching for error code cause tau is being created (debugging).

PHP provides several ways to make a comment, and it all comes from other popular programming languages such as C, C++, and Unix Shell.

1. the method comment Unix Shell

Referred to as a Unix Shell, comment method because of the way this comment comes from a Unix system. This method uses the character mark of the fence or the hash mark (#). PHP will ignore the entire text found after the sign of the fence until the end of the line or the closing PHP tag (which is first found).

Because of its nature that affects only one row only, Unix Shell comment effective Method used to make short comments.

Some programmers also often use the character # to separate parts of the PHP code with other parts, such as the following:

When you create a program code PHP and HTML are inter-related, comment Unix Shell can be used like the following example:

2. the method of C++ comments

This comment method borrow how to make comments from the programming language C++. Similar to the Unix Shell comment method, the method comment C++ is applicable only to a line or until the closing PHP tag, but this time the characters used are two time slash (two slashes), i.e. the “//“.

Because its the same as the Unix Shell, all examples of the sign ‘ # ‘ can be replaced with ‘//’, for example:

3. the method of Comment C

If the method of Unix Shell and C++ comments effective short to make a comment, to make a long comment, borrow it from the PHP language C. method of these comments is also called type comment block because of its nature which must be given a sign close to end the comment.

To start the comment, we write a slash followed by an asterisk (/*). All text after the sign will be interpreted as a comment to PHP find the sign is closed, i.e. the character and followed by a forward slash (*/). Method comments C can include multiple lines.

Here is an example of the use of the method Comment C

Method Comments C is also useful for “commented on” a few lines program so as not to be executed by PHP, such as the following examples:

Namun anda perlu berhati-hati untuk tidak membuat blok komentar yang saling bertumpuk, seperti kode berikut:

In the example above, PHP will fail to run the program code and generate an error caused the comments are berhimpitan (overlapping).

In the next tutorial learn PHP, I will discuss about the essence of the PHP programming language, i.e. a variable. Next on the Tutorial Learn PHP: Understanding variables and Ways of writing the PHP variables.



Please enter your comment!
Please enter your name here