Safe alternatives to PHP Globals (Good Coding Practices)

后端 未结 6 1216
渐次进展
渐次进展 2020-12-03 04:03

For years I have used global $var,$var2,...,$varn for methods in my application. I\'ve used them for two main implementations:

Getting an already set cl

6条回答
  •  -上瘾入骨i
    2020-12-03 04:37

    There are, however, performance and security ramifications of doing it like this.

    To tell you truth, there are no performance nor security ramifications. Using globals is a matter of cleaner code, and nothing more. (Well, okay, as long as you're not passing variables of tens of megabytes in size)

    So, you have to think first, will alternatives make cleaner code for you, or not.

    In matters of cleaner code, I'd be in fear if I see a db connection in the function called showPage.

提交回复
热议问题