How To Comment In PHP Applications

PHP is a very versatile language, allowing for programmers to make applications according to their various tastes or styles. But one thing all programmers should maintain is the ability to comment effectively. In essence, commenting can save hours of time perusing code months down the road- and is often required by employers.

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.

The general public is allowed to view some comments such as HTML comments. PHP really shines in this example, since PHP comments aren’t sent out to the browser and will not be able to be viewed if the script is running correctly. This is great for keeping code secret, as well as mental notes, ideas, and other things developers don’t need competitors seeing.

There are actually three operators that we may use to tell the PHP engine that we want to use a comment. Single inline comments can be used with the “//” and “#” operators. For multiple-line comments, we use “/*” and “*/” respectively to indicate what is a comment and what is actually PHP code. While the first two operators are synonymous, the last one discussed is the only one that can perform multiple line comments with relatively little work.

Unbeknown to most, PHP comments can also be used for more practical scenarios, such as troubleshooting. Expert programmers will find they have a problem with their application, and comment out different blocks of code to see what is causing the error. While it is usually in new code blocks, this method will indeed show that sometimes the problem is due to program code interacting wrong, which can in effect mean the problem is anywhere in the application.

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.

Learn more about how to comment out php and php comments syntax.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Entries and comments feeds. Valid XHTML and CSS. Online Public Relations - Third Party Logistics - Yahoo - Google