double quotes vs. single quotes with concatenation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

double quotes vs. single quotes with concatenation

Post by toasty2 »

Which is better? I hear somewhere that single quotes are faster, but are they still faster when you use concatenation? Like:

Code: Select all

$string = "Stuff: $stuff"; // Double quotes
$string = 'Stuff: '.$stuff; // Single quotes with concatenation
Which is generally quicker and which one do yall use more often?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I use the latter because it is more readable to me. Execution speed of single quotes vs. double quotes is extremely neglible, I really wouldn`t worry about it.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

I agree that the difference should be based only on personal preference. I tend to use

Code: Select all

"alsd hfaj hflkj hsaklf {$myvar} yxc vyx"
but this is do provide consistancy when using array variable which don't normally work in double quotes without the squigglies.

Whatever method you use the key thing is to remain consistent.
Post Reply