Does variable name length matter for performance in PHP?

这一生的挚爱 提交于 2019-12-05 05:00:24

Variable names exist more as a programmer aide - when a program or script is interpreted, these are converted into memory locations. Shorter variables will only negatively impact performance of the programmer(s) when modifying / debugging code in the future.

Obfuscation is a widely used technique that involves replacing variable names with single/multi-character variable names, but that is used in an attempt to make reverse engineering / lifting core technology from projects where the source code is readily available / easily extracted more difficult.

While it may save a byte here and a byte there, no, it does not matter one iota, and you will not see real memory or performance savings by using short variable names.

If you are really worried about memory use and performance, profile your code. xdebug and xhprof are great tools to get it done. You can even install xhprof on your production machines. Once you've actually measured your performance and memory use, then you can target the real problems in your code.

Also, make sure you're running 5.4, if you can. It introduces some huge improvements to both performance and memory use.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!