PHP single quotes Vs double quotes

Any time you put something in “double” quotes, you are asking PHP interpreter to check that content for a variable. So even though the line do not contain variables within the double quotes, PHP will waste precious computing time scanning them anyway.

$sql = 'select * from employee';

will be much faster than

$sql = "select * from employee";

One Reply to “PHP single quotes Vs double quotes”

  1. While this might seem like a big deal, it actually falls under the realm of micro-optimization – and, in most cases, the performance you gain is trivial, and not going to be noticed by any human users.

    Perl happens to do this too, but it converts double-quoted strings without variables inside them into single-quoted at compile time – see this writeup(http://perlmonks.org/?node_id=577891) for more info – although I can’t tell you for sure whether PHP does the same.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.