Comments help to describe the flow and intent of the code.
When the code is quite obvious, it is not productive to repeat it with a lot of comments.
If you comment on the code, you can simply combine it to a single line in most of the cases.
INCORRECT
CORRECT
DocBlock style commenting is something we should use preceding class, method, and property declarations so they can be picked up by IDEs
CORRECT
CORRECT
When the code is quite obvious, it is not productive to repeat it with a lot of comments.
If you comment on the code, you can simply combine it to a single line in most of the cases.
INCORRECT
Code
// Prevent any possible XSS attacks via $_GET.
// Check if we have a stripget($_GET) function request
if (stripget($_GET)) {
// The request found a bad pattern, terminate the script
die("Prevented a XSS attack through a GET variable!");
}
// End of function
CORRECT
Code
// Prevent any possible XSS attacks via $_GET.
if (stripget($_GET)) {
die("Prevented a XSS attack through a GET variable!");
}
DocBlock style commenting is something we should use preceding class, method, and property declarations so they can be picked up by IDEs
CORRECT
Code
/**
* ClassName
*
* @package Package Name
* @subpackage Subpackage
* @category Category
* @author Author Name
* @link http://example.com
*/
CORRECT
Code
class ClassName {
/**
* Encodes string for use in example
*
* @param string $example Input string
* @return string
*/
function encode_example($example)
/**
* Data for class manipulation
*
* @var array
*/