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?
Answer: Use the Syntax "// text" and "/* text */" Comments are usually written within the block of PHP code to explain the functionality of the code.
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 ;-)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With