Re: Questions on user sessions and variable scope.
| From: | Zak Greant | Date: | Tue, 20 Jun 2000 22:06:56 +0000 |
| Subject: | Re: Questions on user sessions and variable scope. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2380@lists.php.net to get a copy of this message | ||
At 03:05 PM 6/20/00 -0700, Warren Vanichuk wrote:
Greetings. Is there any way that I can define a particular set of variables to be global in scope in a single location? Currently I am declaring them global in each and every function that I define, but this is getting rather cumbersome. I would just like to be able to include a file that will declare the variables global in scope, then have any function be able to reference the variable without a scope declaration inside the function itself.AFAIK there is nothing that can do this in PHP.
Reading through the documentation, I found the $GLOBALS associative array, but the examples show it inside a function. If I declare variables global within this array outside of a function definition, will they take on a truely global scope? :)The $GLOBALS array does not make variables global in scope, instead it is an alternate way to access globally scoped variables. For example, these two functions are roughly equivalent. One declares that it wishes to use the globally variable $REMOTE_USER, while the other accesses it via the $GLOBALS array. function test ($var) {
global $REMOTE_USER;
return $REMOTE_USER . $var;
}
function test ($var)
{
return $GLOBALS['REMOTE_USER'] . $var;} HTH, Zak Zak Greant Creative Director Nucleus Information Service Inc. "A camel is a horse designed by a committee." - Alex Issigonis (Designer of the Morris Mini)