Jump to content

[SOLVED] What is the difference between declaring globals and passing them to function


nevesgodnroc

Recommended Posts

I am working on a project that contains an auto responder and contact information collection.

 

I am wondering what is the difference between declaring the scope of my variables to the global scope inside the function or passing the variables to the function.

 

and does php use a call by reference or call by value. I have never seen either of these staements in php yet.

 

I am interested in these answers both from proper code writing as well as server load

 

 

Link to comment
Share on other sites

I think this is somewhat accurate -- please add to this description if I am not accurate, I am very new to this....

 

 

When you create a function you may create unique variables in the function which have a scope of that function only - they are limited to that function only.  For example if function 1 has a variable named $variable1 and function 2 has a variable named $variable1 - both of the $variable1s I just described are different variables even though they have the same name.  Now if we start over and you use a predefined or declaired global variable named $variable1, that means that now they are the same variable.

 

I think for the utility you describe you need not worry about the server.   

 

If you think about a page of script as the entire world of that script - local variables only (I mean only variables on the script page I am talking about) - a global variable is the SAME variable on the entire page, no matter where it is.  Non-globals are limited in scope or confined to their functions unless otherwise defined.  I think.

 

 

Marc

 

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.