Performance: " or ' PHP [duplicate]
Asked Answered
D

2

6

I'm working on a big project in php and I need to make sure it's all fast. So I'm wondering: what is faster to use, " or ' ? (Eg: $_SESSION['example'] or $_SESSION["example"])

Dehumanize answered 14/12, 2015 at 15:4 Comment(7)
everything within " " wil be analysed and everything within ' ' notErnestineernesto
Write a benchmark and test it. In my experience, " is very slightly (~4%) faster. But note: this is probably a case of very premature optimization.Crustal
possible duplicate https://mcmap.net/q/101634/-speed-difference-in-using-inline-strings-vs-concatenation-in-php5Dumpy
@Ernestineernesto - not true, even strings inside ' need to be analysed for escape charactersAphorism
On a big project - It is most likely that database access will be a performance issue rather than parsing strings natively in PHP (which is a none issue anyway)?Downall
You might save a moment when typing single quoted keys, as you won't have to hit the shift key. (Edit: true on US Qwerty layout, not on every layout i.e. Azerty.)Indignant
That sounds like an interesting project to work on. There is a lot to be learned from working on that project. Thanks for the update - I think you will have a lot of fun and interesting times - always try an enjoy it.Downall
A
10

You shouldn't even care about this. It makes no real difference. No practical impact.

http://nikic.github.io/2012/01/09/Disproving-the-Single-Quotes-Performance-Myth.html

https://speakerdeck.com/dshafik/phpaustralia-2015-php-under-the-hood


Lets use the same benchmark data from the post by Mark Smit:

For a real speed benchmarks between quotes you can look at http://www.phpbench.com/

Q: Is a there a difference in using double (") and single (') quotes for strings. Call 1'000x

A: In today's versions of PHP it looks like this argument has been satisfied on both sides of the line. Lets all join together in harmony in this one!

Amata answered 14/12, 2015 at 15:18 Comment(0)
S
-5

You should use ' because everything within " is analized, which makes it perform a lot slower. Right now magic quotes are even depricated. More information about that can be found on the php website

For a real speed benchmarks between quotes you can look at phpbench

Sherrill answered 14/12, 2015 at 15:9 Comment(1)
magic quotes has NOTHING to do with the choice of ' or "...Antichrist

© 2022 - 2024 — McMap. All rights reserved.