By using comments you can describe what your PHP script does and how it works. Commenting your code is one of the most important things a programmer can do and it’s also one of the things programmers don’t do enough. You should develop the habit of commenting your code so other programmers can easily see what you were doing and to remind yourself of what you did if you come back to your code later on.
Comments are just for us humans. PHP ignores them, as long as you specify they are comments. You don’t need to comment everything, like very basic statements, but you should comment anything that took a little bit of thought.
There are many different types of comments:
Single line comment using //
<?php// This is an example single line comment. Just type slashes in front of the lines// to let PHP know that it's a comment.echo"Hello"." universe!";// You can also put them after PHP code, like this.?>
Single line comment using #
<?php# This is another way to make single line comments.
# Using slashes is more common.
echo"Hello"." universe!";?>
Multi line comments using /* and */
<?php/*
This type of comment lets you easily
write in many lines without having to
constantly type slashes
*/?>
Please note that putting comments inside of a comment may cause an error, so avoid doing that.
<?php/* This is the first line of a comment.
/* Oops. This is a comment within a comment. PHP won't like this. */*/// Don't do // this either // as there is no point.?>
So now that you have an understanding of commenting your code, the next step is just remembering to do it. If you eventually start creating applications with dozens or hundreds of PHP files, you’ll be extra glad you did, trust me.
Before proceeding to the next section, try opening the hellouniverse.php file we created earlier and add some comments to it.
25 Aug 09 PHP Programming Tutorial: Using Comments
By using comments you can describe what your PHP script does and how it works. Commenting your code is one of the most important things a programmer can do and it’s also one of the things programmers don’t do enough. You should develop the habit of commenting your code so other programmers can easily see what you were doing and to remind yourself of what you did if you come back to your code later on.
Comments are just for us humans. PHP ignores them, as long as you specify they are comments. You don’t need to comment everything, like very basic statements, but you should comment anything that took a little bit of thought.
There are many different types of comments:
Single line comment using //
Single line comment using #
Multi line comments using /* and */
Please note that putting comments inside of a comment may cause an error, so avoid doing that.
So now that you have an understanding of commenting your code, the next step is just remembering to do it. If you eventually start creating applications with dozens or hundreds of PHP files, you’ll be extra glad you did, trust me.
Before proceeding to the next section, try opening the hellouniverse.php file we created earlier and add some comments to it.
Go back to PHP Programming: The Basics.
Tags: commenting, comments, learn, php, programming