As far as I remember, concatenating PHP variables (as in the third example) is faster than using "$var1 $var2" given the combination of variables and constant strings, since each token is evaluated on the fly (which is bad).
So, between 2 and 3, I think it depends on the context: if you have a long string with a combination of variables and constants, then method 3 will be faster. Otherwise, if it is identical to your example, 2 may be faster (however, the difference is not significant, and therefore should be controversial).
Using the template engine will always be slower than the source code.
Now , if you donβt have a very good reason not to use the template engine, you should use all of its accounts. Why?
- Separation of problems . Your PHP should not care about your HTML and vice versa.
- Service . Maintaining can be a nightmare when you mix HTML and PHP (or any other language, for that matter) and should be avoided at all costs (unless you are doing something dazzlingly trivial).
Demian brecht
source share