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, 01:16 #1
- Join Date
- Aug 2008
- The Netherlands
- 153 Post(s)
- 3 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?Rémon - Hosting Advisor
SitePoint forums will switch to Discourse soon! Make sure you're ready for it!
Minimal Bookmarks Tree
My Google Chrome extension: browsing bookmarks made easy