Jump to content

Scope of globals


Nolongerused3921

Recommended Posts

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.
Link to comment
Share on other sites

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.


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.