As far as I can see (browsing popular PHP code in GitHub) there are many people not using string interpolation:
$loader->load($config['resource'].'.xml');
Versus:
$loader->load("{$config['resource']}.xml");
Is there any reason (i.e. performances) for not using string interpolation?
No, there is no reason not to be using string interpolation in PHP.
While there are tiny differences in how PHP handles string interpolation and concatenation internally, those differences are so small that they are barely measurable in practice, and should therefore be left to PHP to handle.
If or when you see benchmarks, for working with strings in PHP, the thing to look for is usually the iteration count. In order to get measurable results you need to set n
to some highly exaggerated value, which never occurs in the real world.
To wrap up, optimizing how you work with strings in PHP does not make much sense. Instead, you should focus on problems that actually have a noticeable effect on the performance of your website; caching, database stuff and, especially, the front end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With