Hacker News new | ask | show | jobs
by lomegor 4994 days ago
Although I understand that you want something to run faster, preemptive optimization is not always the best solution. It can lead to bad code and to weird behaviour. For example, arrays and especially associative arrays should not go inside double quotes, most of the times (I'm not sure if it's even possible). That way, double quotes are only useful with single variables, meaning that sometimes, even with double quotes, you would need to use concatenation.

And that's not even taking into account sanitation, because with double quotes it's easier to avoid it, and harder to notice.

I prefer choosing one of those types of quotes and sticking to it throughout the code. It makes code more readable and makes it easier to notice bugs and optimization problems.

1 comments

For double quotes you can use curly braces instead of concatenation. $foo = "I like {$hacker['news']}"; depending on how you want it evaluated you can drop the dollar sign on the outside of the curly brackets as well.