mike177 Posted March 10, 2008 Share Posted March 10, 2008 Hi, I have been using globals alot in my scripts and app's and theres alot of security risks with them so my question is how to get around them. e.g not use them. Does anyone know any methods? thanks in advance for any help. Quote Link to comment Share on other sites More sharing options...
KrisNz Posted March 10, 2008 Share Posted March 10, 2008 You can use a registry class. http://www.patternsforphp.com/wiki/Registry Quote Link to comment Share on other sites More sharing options...
btherl Posted March 10, 2008 Share Posted March 10, 2008 Using OOP eliminates the need for many globals which can be made "per object instance". An alternative to a registry class is to have a single global array storing all your globals. Then you just have to worry about not clobbering that single array. If you're keen about not polluting the namespace, you can make the "global" variable array static inside a function (but then the function itself is in the global namespace, so you haven't gained much). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.