Block-level comments are useful for commenting out an entire block of code in PHP, CSS, and other code contexts.
/* $this = 'code is deactivated'; $and = 'so is this'; */
The only problem with this is that when you go to re-activate this code, you have to change both the opening and closing comment markers. That’s a pain.
While I was at WordCamp NYC last week, I saw Daisy Olsen using a very clever trick in her lightning round talk.
/* $this = 'code is deactivated'; $and = 'so is this'; /**/
See what she did there? The closing comment marker is preceded by another opening marker. Because comment blocks can’t be nested, this second opening comment marker is ignored. This enabled her to re-enable this code by removing the opening marker.
$this = 'code is reactivated'; $and = 'so is this'; /**/
Brilliant! I can’t believe I haven’t seen this before. The one downside to this is that you are deleting two characters and destroying the opening marker. Here’s an even better method.
//* $this = 'code is reactivated'; $and = 'so is this'; /**/
By adding a slash in front of the opening comment marker, I comment out the comment marker. It only takes one key press, and the corpse of the original opening marker is retained, allowing you to reinstate it with the deletion of a single character.
Props to Aleem Bawany for the second trick (he uses
//*/ as the closing comment, which works pretty much the same way).
What other commenting tricks do you know?