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

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.