Effective Use Of PHP Comments In Web Development 0
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.
PHP comments may only be seen by developers, since the PHP engine doesn’t pay attention to remarks declared as comments. This is quite handy for developers, who can make visible notes on their source code all while the visitor to the webpage is kept in the dark about any such comments.
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.
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
In the end, there is a lot to gain from using PHP comments. They are quite functional for saving time, and also serve their purpose in troubleshooting. For more information on the idea of using comments effectively, check out local bookstores and online resources for more material.
Learn more about php comment tag and php comments syntax.