Page 2 of 2
Posted: Fri Dec 23, 2005 2:47 pm
by BDKR
Ambush Commander wrote:But it's annoying when you're writing a sentence.
Code: Select all
$string = 'But it's annoying when you're writing a sentence.';
Parse error! ARGH!
LOL! True that! Guess it depends on the situation.
Posted: Fri Dec 23, 2005 9:40 pm
by Jenk
Code: Select all
$string = 'But it\'s annoying when you\'re trying to write a sentence!';
:p (same problem with double quotes .. )
I use single quotes, doubles if I need a variable parsed inline.
Using doubles unecessarily (i.e. on a literal/static string) is less efficient than single quotes.
Why?
Single quotes says to PHP: "Here, take this value as it is."
Doubles say: "Read through me first, and check if there are any variables that need parsing and replacing."
IMO singles are better than doubles

Posted: Fri Dec 23, 2005 9:43 pm
by Ambush Commander
Maybe the ultimate quote is a backslash... almost never used, and when used, well, you'd have to escape it anyway. Don't know how the lexer would make sense of it though.
Edit - as to your reply, ideally, we wouldn't have to escape anything at all. I hate writing a string, firing up PHP, discovering a parse error, then remembering that I had forgotten to escape my quotes. It's really annoying.
Posted: Fri Dec 23, 2005 9:54 pm
by Jenk
use blocks then
You can change BLOCK for any phrase/char you like.
Posted: Fri Dec 23, 2005 9:57 pm
by Ambush Commander
I've just heard heredoc is clunky, slow and interpolates variables...
Posted: Fri Dec 23, 2005 9:59 pm
by Jenk
aye, they do.
I don't use them as they make reading code terrible.
Posted: Fri Dec 23, 2005 11:16 pm
by josh
Jenk:
have you benchmarked the actual difference in time between single and double quotes?
I just did, it's about .000004 slower to use doubles quotes to assign an average string with one variable in it....
it would only be noticeable if it was done 250 thousand times or so
Posted: Sat Dec 24, 2005 12:08 am
by Jenk
regardless of how small the difference, that still shows it is more efficient to use single quotes

Posted: Sat Dec 24, 2005 5:17 am
by Buddha443556
As much as an optimization nut as I am, I still regard this as code standardizarion issue. Just be consistant.
Can't believe this topic got two pages!

WTG Method Man!
Posted: Sat Dec 24, 2005 6:22 am
by patrikG
Buddha443556 wrote:As much as an optimization nut as I am, I still regard this as code standardizarion issue. Just be consistant.
Can't believe this topic got two pages!

WTG Method Man!
lol, yeah indeed. I tend to not really bother too much with double or single quotes, it's usually single quotes. I find enough else in my code to optimise, simplifying logic being the number #1 thing. It's always amazing how much you can optimise when you refactor your code after a couple of months.