NYCPHP Meetup

NYPHP.org

[nycphp-talk] single quote vs. double quote

Hans Zaunere lists at zaunere.com
Mon Apr 2 22:09:05 EDT 2007



csnyder wrote on Monday, April 02, 2007 10:05 PM:
> 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.

True, but I still like the ability to quickly look at a string and know
wheather it should contain variables or is static :)

H




More information about the talk mailing list