Using Quotes

Carl on jan 26th 2011 08:53 am | Tags: ,

Quite a few (starting) programmers use the double quote style. Often they say it is because it’s easier or better readable. However, PHP is an interpretive language and will interprete everything enclosed in double quotes. This may affect the speed negatively when using large blocks of code.

Text enclosed in single quotes will not be interpreted and shall not influence your code’s speed negatively. Having a site with high trafic and a lot of code to work through, it is best practice to use single quote style and concatenation.

E.g.:
echo “Welcome to {$_SERVER[''HOST'']} bla bla, $_today”;
echo ‘Welcome to ‘ . $_SERVER['HOST'] . ‘ bla bla, ‘ . $_today;

Filed in PHP @en

Comments are closed.