nevesgodnroc Posted November 25, 2007 Share Posted November 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78789-solved-what-is-the-difference-between-declaring-globals-and-passing-them-to-function/ Share on other sites More sharing options...
revraz Posted November 25, 2007 Share Posted November 25, 2007 PHP can use either pass by value or pass by reference. You would use the & before the variable name to pass by reference. Quote Link to comment https://forums.phpfreaks.com/topic/78789-solved-what-is-the-difference-between-declaring-globals-and-passing-them-to-function/#findComment-398722 Share on other sites More sharing options...
odisey Posted November 25, 2007 Share Posted November 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78789-solved-what-is-the-difference-between-declaring-globals-and-passing-them-to-function/#findComment-398728 Share on other sites More sharing options...
rarebit Posted November 25, 2007 Share Posted November 25, 2007 I'll point you to some Sunday reading --> http://uk3.php.net/manual/en/language.references.php Quote Link to comment https://forums.phpfreaks.com/topic/78789-solved-what-is-the-difference-between-declaring-globals-and-passing-them-to-function/#findComment-398729 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.