Something I’ve noticed from php developers regardless of experience level is the misunderstanding of when to use single quotes (‘) or double quotes (“) in their strings. If you’re coming from a language such as Javascript, the quote style you use is really a matter of preference. PHP is different. Technically, either will appear to work all the same but there is a design intention to their proper use and misusing them can make for ugly code and also take a (albeit, probably small) performance hit.

Let’s look at the following code:

$x = 'string';
echo "This $x is an example.";

PHP evaluates the the contents of the string – everything between the double-quotes for variables and control characters (line breaks ‘\n’, tabs ‘\t’, etc). As expected, the output is:

This string is an example.

Single quotes behave differently. Lets look at the code again but with single-quotes.

$x = 'string';
echo 'This $x is an example.';

Outputs:

This $x is an example.

PHP essentially ignores the contents between the single-quotes. $x is not a variable in this case, it’s just part of the string. For the variable to be evaluated, the string needs to be escaped.

$x = 'string';
echo 'This ' . $x . ' is an example.';

PHP echoes the contents between the single-quotes and concats the value of $x to it.

Something you’ll often see is a double-quoted string, escaped for variables. Although php will evaluate this and display the output correctly, it’s wrong. The string’s content is already going to be evaluated for variables so there is no need to escape. For example,

$x = 'string';
echo "This " . $x . " is an example."; // Works, but redundant

PHP has more work to do if you use double-qutoed strings. As i’ve said, the contents and all it’s characters are going to be evaluated regardless if the string contains variables or not.

Let’s look at some simple benchmarks.

$start = microtime();
for ($i = 0; $i < 10000; $i++) {
    echo 'This string is an example.' . PHP_EOL;
}
$end = microtime();
$elapsed = $end - $start;
echo $elapsed . ' seconds have passed.';

Outputs:

...
This string is an example.
This string is an example.
0.035564 seconds have passed.

Now with double-quotes:

$start = microtime();
for ($i = 0; $i < 10000; $i++) {
    echo "This string is an example." . PHP_EOL;
}
$end = microtime();
$elapsed = $end - $start;
echo "$elapsed seconds have passed.";

Outputs:

...
This string is an example.
This string is an example.
0.964306 seconds have passed.

Using double quotes results in a -0.92 seconds performance decrease. :(

It’s probably not worth refactoring all your old code to correct any misused quotes but any future development should keep the differences between them and their proper uses in mind.

Further reading:
http://php.net/manual/en/language.types.string.php