Lazy Block Comment Trick

If you like using block comments then you might like this little time saver to toggle block comments much more lazily. The lazy block comment syntax uses /* and //*/ instead of the conventional /* and */. I have not seen this syntax anywhere else but I’ve been using it for years. Here is how it looks in code:

$id = get_user_id();
$age = get_user_age($id);

/*
debug_output($id);
debug_output($age);
var_dump(get_user_data($id));
//*/

$data = get_user_data($id);

To uncomment the entire block just add an extra / to the opening comment, essentially commenting out the opening block comment by converting it into an inline comment. This makes it very easy to toggle the entire comment block:

$id = get_user_id();
$age = get_user_age($id);

//*
debug_output($id);
debug_output($age);
var_dump(get_user_data($id));
//*/

$data = get_user_data($id);

The whole block is now uncommented because the starting and ending block comments are themselves commented out using the inline comment syntax //.

From now on when you consider block comments, remember the lazy syntax: /* and //*/ to comment. //* and //*/ to uncomment.

10 Responses



This article is no longer open for comments