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. Link to comment https://forums.phpfreaks.com/topic/95320-how-to-avoid-using-globals/ 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 Link to comment https://forums.phpfreaks.com/topic/95320-how-to-avoid-using-globals/#findComment-488237 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). Link to comment https://forums.phpfreaks.com/topic/95320-how-to-avoid-using-globals/#findComment-488296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.