Manquer
Manquer

Reputation: 7647

Difference between # and // in php?

<?php
    # some comment
 ?>

and

<?php 
   // some comment
?>

are used for single-line code commenting in PHP, and that former comes from shell scripting and // comes from C++.

However I am curious to know if there are any differences between using // and # for single line commenting and anyone has come across cases specific cases where one or other should not be used.

Only difference I could think of is there is one character in '#' and two in '//' so perhaps will there in larger scripts some small size and/or performance gains ??

Upvotes: 5

Views: 1051

Answers (1)

Derfder
Derfder

Reputation: 3324

For me it's easier to type // by double pressing the key on my keyboard moving just my right pinky one key down and pressing it two times.

If I want to do # I need to use both hands and the movements are "bigger" ;). It's the same for echo and print.

But in print and echo "scenario" you can hear an argument that one function is a little slower, however I am not sure right now which one ;) but it's really something that is no deal-breaker when optimizing for code I guess.

According to this topic echo is a little faster: Should I use echo or print in php scripts?

Upvotes: 3

Related Questions