Saving Time By Using Comments In PHP Programming
December 29th, 2008 . by Learn For FreeWeb development students that are just starting out often overlook the usage of comments in PHP. It’s rather unfortunate, since using comments actually saves more time in the long run, although new students only see the short-term benefits and thus don’t make use of them. Such students should take heed to this advice, since it’s often even required my 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.
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.
When we wish to tell the PHP engine that we want to make use of a comment, we have three different structures to select from. The first two are “#” and “//” and are considered to be single line comment structures. For commenting on multiple lines, we use “/*” and “*/” in that order. Multiple line comments can be created through multiple single line comment calls, but this is of course redundant.
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.
One big use of commenting in PHP is to use comments in selection structures, whereas comments are placed in every possible choice given. Often, developers close selection structures, such as the IF structure, without commenting what each choice does since we don’t always use every choice. But by defining each choice early on, this saves quite a bit of time down the road once developers start nesting loops and selection structures inside each other.
Final Thoughts
The Internet is full of many examples of how to creatively use PHP comments. Try scouting out some websites for more information on the usage, concept, and execution of comments to get better experience with this blessing. As developers find, an early history with commenting in programming is always the best route.
Learn more about php block comment and add comments to php.