Jump to content

global variable question


mindapolis

Recommended Posts

This is far too vague to be answered properly.

 

The "global" keyword is not to be used like that, you use it for importing variables INTO functions, not usually for exporting them out into the global scope.  That being said, it's almost always the wrong decision anyway.  Globals are dangerous and break the flow of your application.

 

Anything that exists in the global scope is automatically available in the global scope (persisting through include files).  Things in the global scope are not available inside of functions or classes.

 

Any items a function needs to do its job should be passed into the function as arguments.  Any items the function needs to change should be returned by the function OR passed in by-reference so they can be changed inside the function without having to be returned.  In general, "global" should not appear in your codebase.  It's a hack.

 

-Dan

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.