Search code examples
phpstringquotes

Does PHP work harder (i.e. more processing) on double quotes?


Is it true that PHP adds more processing for quoted strings because it searches for variables?

If so, is it better to use single quotes and break them up for variables. Or, what method is better?


Solution

  • Yes, since double quotes allow PHP to perform variable interpolation, there will be a (very very small, even I dare say almost theoretical) performance hit (tokenizer only) as it finds variables whose values to replace into the strings.

    However, performance should not be the deciding factor when choosing between single quotes or double quotes. Readability would be a slightly better concern. That is, performance of one's brain would be affected more than performance of the interpreter.