Nolongerused3921 Posted January 22, 2007 Share Posted January 22, 2007 I'm about to make a drastic change to my site engine, however before doing so I want to confirm GLOBALS (I rarely use them)....Right now I'm defining classes like this:[code=php:0]$filesys = new filesys();$parser = new parser($mysql,$settings[0]['root_dir']);$user = new user($mysql,$parser,$default_group);$articles = new article($mysql);[/code]As you can see I pass variables through like that, however this is getting to be a major problem... So I'm wondering, how global ARE global variables? Can I define a class definition as a global and access it's functions in another class (A whole other file altogether)...Do I have to define this global before I require it, or does php process globals prior to executing any other code.The reason I ask is because I need to reuse the same basic code over and over again in multiple modules (Article module defined above, for instance*), and I [b]really[/b] hate having to pass class definitions through the startup function, or even a class function ($article->update($class_definition, $othervariable); )*You can't tell from the code, but modules are automatically loaded based on class definitions... So if I assign "new article();" to a variable, it will automatically load /modules/article.mod.php prior to defining the class. Quote Link to comment https://forums.phpfreaks.com/topic/35179-scope-of-globals/ Share on other sites More sharing options...
bibby Posted January 22, 2007 Share Posted January 22, 2007 Anything you declare or use in your classses are considered globally accessible.In some instances though, you may want to process references to these objects so that you don't screw up the original.[code]$clone &= $filesys;doSomethingTo($clone);[/code]You don't mean SUPER GLOBALS do you?I'm not making any connection between your question and example data. Quote Link to comment https://forums.phpfreaks.com/topic/35179-scope-of-globals/#findComment-166152 Share on other sites More sharing options...
448191 Posted January 22, 2007 Share Posted January 22, 2007 If I understand your question correctly, you're in need of a Registry.Check out this article: http://www.phpit.net/article/using-globals-php/1/ Quote Link to comment https://forums.phpfreaks.com/topic/35179-scope-of-globals/#findComment-166177 Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 That did it, thanks 448191 - I now love this mock registry :D Quote Link to comment https://forums.phpfreaks.com/topic/35179-scope-of-globals/#findComment-166200 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.