Should you use single or double quotes in your PHP/Python code?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


7 points

According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?



5 points

Personally I stick with one or the other. It doesn't matter.

Both would work but one may ask, so what is the big deal? why is it better?

Double Quotes way :

<?php
<?
Echo 
"<TABLE BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"0\">";
?>

Single Quotes way :

<?php
<?
Echo 
'<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="0">';
?>

In this example you can see that we don't need to add escape characters for each Double Quote we want to echo as HTML.

This, by its self is a good enough reason to migrate, however, a 2nd reason is performance.
Using Single Quotes is always at least as fast as Double Quotes and in some cases faster by hundreds of percents.

Anonymous's picture
Created by Anonymous
-7 points

I prefer single quotes because its only one keystroke instead of two. That is, I don't have to mash the shift key to make single quote.

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.