29th Dec 2008
How To Comment In PHP Applications
Web 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.
Comments aren’t parsed by the PHP engine, so they are only visible to those who are viewing the original source code of the file. This is great for documenting what each code block does, all while keeping the casual visitor to a website oblivious to the extra comments present on the application they are using.
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.
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.
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.
In Conclusion
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 comments syntax and php comment line.
Web 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.
Comments aren’t parsed by the PHP engine, so they are only visible to those who are viewing the original source code of the file. This is great for documenting what each code block does, all while keeping the casual visitor to a website oblivious to the extra comments present on the application they are using.
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.
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.
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.
In Conclusion
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 comments syntax and php comment line.
Posted in Computers, General, Reference And Education | No Comments »