scrubbicus Posted May 20, 2009 Share Posted May 20, 2009 What's the best way to make variables global so that absolutely everything can access it? Right now I currently have my variables files required on index.php so that every file can access it but I'm trying to access some of those variables from within my classes and they can't find those variables. I've also tried requiring onload off my main initialize class that variables file but then anywhere I call that variable outside a class it can't find it. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 20, 2009 Share Posted May 20, 2009 You shouldn't be attempting to access variables from outside the class like that. It totally ruins the point of OOP. If you must though, use (as you said) global variables: http://uk3.php.net/manual/en/language.variables.scope.php Quote Link to comment Share on other sites More sharing options...
scrubbicus Posted May 26, 2009 Author Share Posted May 26, 2009 I'm slowly getting the hang of OOP but I think I'm still using the entirety of it wrong. Currently I'm making everything in one huge giant class and defining all the definite private variables in that class the I can use them throughout. My construct for that class is the MySQL connect and MySQL select db and I call this class at the beginning of index.php. $initialize = new initAll(); then I just make all my functions and variables in that class through the script I feel like I'm definitely not using OOP correctly and capitalizing on parent/child relationships which I haven't really gotten to yet because when I do it becomes a hassle for me to call functions and variables from different children, from the parent, or from classes entirely different. 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.