Skip to content

no-double-quote #7

@philsturgeon

Description

@philsturgeon

While you have linked to Nikita's article Disproving the Single Quotes Performance Myth, your advice is still incredibly generalized and not entirely accurate.

I wrote this up on PHP The Right Way: Strings

Scroll down to this bit:

Which is quicker?
There is a myth floating around that single quote strings are fractionally quicker than double quote strings. This is fundamentally not true.

If you are defining a single string and not trying to concatenate values or anything complicated, then either a single or double quoted string will be entirely identical. Neither are quicker.

If you are concatenating multiple strings of any type, or interpolate values into a double quoted string, then the results can vary. If you are working with a small number of values, concatenation is minutely faster. With a lot of values, interpolating is minutely faster.

Regardless of what you are doing with strings, none of the types will ever have any noticeable impact on your application. Trying to rewrite code to use one or the other is always an exercise in futility, so avoid this micro- optimization unless you really understand the meaning and impact of the differences.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions