NYCPHP Meetup

NYPHP.org

[nycphp-talk] single quote vs. double quote

csnyder chsnyder at gmail.com
Mon Apr 2 22:05:19 EDT 2007


On 4/2/07, David Krings <ramons at gmx.net> wrote:
...
> $langfile = fopen('$langfileloc', 'r');
> and constantly had it fail.
...
> Which makes me wonder as some long time ago we
> had this nice discussion that ended with sth like "one needs only the
> single quote for everything in PHP".
>

Ah, no. The discussion probably went along the lines of "use single
quotes for faster program execution," because, as you learned, PHP
does not need to check for and evaluate variables inside of
single-quoted strings.

But really, all you had to do was not quote at all.
$langfile = fopen( $langfileloc, 'r' );

The difference would come into play if you wanted to, say, add a file
extension to the end of $langfileloc. In that case, fopen(
$langfileloc.'.txt', 'r' ) would be infintissimally faster than fopen(
"$langfileloc.txt", 'r' ), because concatenation is supposed to be
faster than string evaluation. Hans Z. will likely point out that
fopen("{$langfileloc}.txt", 'r') is even faster, because concatenation
is too slow for some folks.

Processor speeds being what they are, the only good reason to use
single quotes is so you don't have to use the shift key while you type
your code.

-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list