Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP comments: # vs. //

Tags:

Lately I've been using # instead of // for doing single line comments inside my code. However, I see most of the people prefer //.

Is there a particular reason for preferring them instead of #? Performance? File weight? Anything?

like image 484
MarioRicalde Avatar asked Dec 20 '09 11:12

MarioRicalde


People also ask

How do you add comments within a PHP file?

Answer: Use the Syntax "// text" and "/* text */" Comments are usually written within the block of PHP code to explain the functionality of the code.


2 Answers

It doesn't change a single thing, I'd say ; it's just a matter of habits :

  • // comes from C, and exists in several languages used by lots of people.
  • # comes from shell and Perl, and exists in not as many "important" languages as // -- so less people use it.

And why are those two both available in PHP ? Well, PHP has been built with people knowing both C, Shell, and Perl, and they have brought what they liked from those languages ;-)

like image 183
Pascal MARTIN Avatar answered Oct 08 '22 14:10

Pascal MARTIN


I'd probably stick with // simply because it's the same in JavaScript, and when you code PHP, you're likely going to have some JavaScript in your files as well. (Most websites use JavaScript nowadays.)

This way, your comments look the same, regardless of the language, and it'd ease readability a small bit.

like image 21
Steffen Avatar answered Oct 08 '22 14:10

Steffen