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

 

 

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

 

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.