> > Or, so you don't have to specify all the variables you are using
> > as globals (especially if you are using *alot* of them), you can
> > use:
> > $GLOBALS[SCRIPT_FILENAME];
> What's the gain? 'global ' has 7 characters, whereas '$GLOBALS[]' has
> 10 characters. So, you don't type less. And with using global(), the
> code is more orderly, and thus easier to read.
True. But take the following function:
function processLotsOfFormVars() {
global $fieldOne, $fieldTwo, $fieldThree, $fieldFour;
global $fieldFive, $fieldSix, $fieldSeven;
global $PHP_SELF, $REQUEST_URI;
global $HTTP_REFERER;
echo "Field One is: $fieldOne<br>\n";
echo "Field Two is: $fieldTwo<br>\n";
// etc
}
OR you can do it this way:
function processLotsOfFormVars() {
echo "Field One is: $GLOBALS[fieldOne]<br>\n";
echo "Field Two is: $GLOBALS[fieldTwo]<br>\n";
// etc
}
I've done it both ways. I'm not advocating using
"$GLOBALS[var_name];" over "global $var_name",
just that it is an alternative if you are using alot of global
variables in a function. Plus, if the function gets large,
it's easier to see where the value is coming from by using
the $GLOBALS variable.
That's all I was saying.
Chris