scottnicol Posted November 4, 2010 Share Posted November 4, 2010 Hi, In all my classes, I need to declare globals for everything else, from site variables even to objects (other classes). I obviously don't want to as globals are horrible and I need to have functions clean without globals. I have included a list of all the global vars in the construct and it still doesn't work. Example: start.php <?php $vars = array(some values); $some = more; $variables = foo; $helper = new Helper(); $home = new Home(); This is a little bit simplistic, but for some reason, the variables just don't want to go in the main class without a global. Functions will not run if they require any of these variables. Quote Link to comment https://forums.phpfreaks.com/topic/217778-need-to-global-variables-to-work-in-functions/ Share on other sites More sharing options...
AbraCadaver Posted November 4, 2010 Share Posted November 4, 2010 That is so simplistic that I have no idea how to help you. Especially using objects there are many ways to do things without relying on globals. Quote Link to comment https://forums.phpfreaks.com/topic/217778-need-to-global-variables-to-work-in-functions/#findComment-1130404 Share on other sites More sharing options...
MasterACE14 Posted November 4, 2010 Share Posted November 4, 2010 pass them as an argument Quote Link to comment https://forums.phpfreaks.com/topic/217778-need-to-global-variables-to-work-in-functions/#findComment-1130407 Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2010 Share Posted November 4, 2010 Functions and class methods have parameter lists for a reason, so that you can pass them parameters at runtime. Quote Link to comment https://forums.phpfreaks.com/topic/217778-need-to-global-variables-to-work-in-functions/#findComment-1130408 Share on other sites More sharing options...
scottnicol Posted November 4, 2010 Author Share Posted November 4, 2010 Funnily enough, I just made a function to pass them, and it is working. I forgot to check back and tell you that I fixed it though... Doh! Thank you ever so much for the help though, your advice would have helped me! Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/217778-need-to-global-variables-to-work-in-functions/#findComment-1130416 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.