PHP - performance and memory issue with global variables

不打扰是莪最后的温柔 提交于 2019-11-29 08:46:33

Your global variables are already accessible in $GLOBALS['foo'], $GLOBALS['bar'] etc. This is a clearer indication inside function scope that they come from the global scope than using the global keyword. Should not affect performance in any meaningful way.

Many will tell you that best practice is to avoid global variables in the first place and instead pass variables through function calls and object constructors.

Both are pretty bad. I would suggest using a singleton, or static classes.

As for memory uses, there would be no noticable difference.

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