View Poll Results: Single quotes or double quotes?
- 90. You may not vote on this poll
Results 1 to 25 of 72
Thread: Quoting strings: what do YOU do?
Sep 29, 2008, 00:16 #1
- Join Date
- Aug 2008
- The Netherlands
- 120 Post(s)
- 2 Thread(s)
Quoting strings: what do YOU do?
As you all probably know, there are different types of string quoting in PHP.
Let's start with single quote vs double quote:
$bar = "foo";
print "hello $bar"; // prints "hello foo"
print 'hello $bar'; // prints "hello $bar"
print "test"; // prints "test"
print 'test'; // also prints "test"
print test; // assuming 'test' is not defined as a constant, also prints "test"
The first example (print "test" also isn't great, because the interpreter has to scan the whole string for occurrences of variables. For this short string this isn't any problem, but for larger strings it might become noticeable.
For these reason I personally ALWAYS stick to single quotes.
What do you use?The 2013 SitePoint Awards - Nominate your heroes now!
Rémon - Hosting Advisor
Minimal Bookmarks Tree
My Google Chrome extension: browsing bookmarks made easy