Font Size : Increase font size Increase font size Decrease font size
Techie Stuff Explained

«     »

'font-style:italic;' class='uawbyline'>by Chris Channing

Because of how PHP is structured, which is to say it is done so that anyone can use it according to their own style, developers don’t have to make use of PHP comments. But the truth is, most professional web developers, if not all, stress that making use of comments in PHP is vital in keeping organization and improving readability for future use.

The reason comments are so handy is because they are only viewed by those looking at the source code of the original file- not the viewer of the website. Best yet, they aren’t even visible to those who try to view the source code of the website, since PHP code is hidden from the browser when being properly used.

Unlike HTML comments, PHP comments aren’t even visible in the source code of a website. HTML comments are visible to the general public, which can potentially lead to the stealing of code or may even help hackers exploit applications. PHP comments aren’t output to the browser at all, so they are completely safe from prying eyes.

Comments are created with three different calls. For comments that span two or more lines, we have to use “/*” and “*/” – and “#” or “//” for single line comments. Comments in PHP can actually be placed directly after real PHP code, above it, or below it. This leaves a lot of creativity in how developers document their code according to their style and tastes.

When problems arise, and they do arise often, developers need to find out ways to solve the problem and continue with their development. This process, troubleshooting, can be done with commenting as well. By commenting out new and old code blocks alike, we can determine which blocks of code are throwing errors and which are considered “clean” for usage. This is actually used quite commonly, despite most thinking comments are only useful for documentation.

Commenting in PHP is also great to use in selection structures, since PHP has long been known as a hard to scale language. Once files start getting big, it can be dizzying to try and remember which loops and selection structures go where, and what they do. By commenting out every closing bracket, and what it is in relation to, the problem is easily fixed. This is often mandatory for programmers who work for employers.

Final Thoughts

PHP Comments are quite handy as we can see, more so than most would think. From troubleshooting to simple documentation, the three methods of commenting have a lot of use to the proper programmer. For more information on comments in PHP, and in other languages, check out more books, articles, and magazines for a more detailed guide in using them effectively.

About the Author:

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Close
E-mail It