Entry
What is the scope of a global (page, session or otherwise).
Feb 18th, 2008 19:28
dman, Paul Kenneth Egell-Johnsen, Peter Boritz, http://www.ttnr.org
AFAIK global scope is for all included files and within all control
structures (switch, for, if, foreach, do, while etc) encountered within
these files.
The reverse way to see this is to say that everything outside a function
or a class is in the global scope.
Globals are fetched either by using the global keyword:
global $YourGlobalVar;
echo $YourGlobalVar;
or through the global variable list:
global $GLOBALS;
echo $GLOBALS["YourGlobalVar"];
The definition means that everything defined within a control structure
is also global, so be careful with your counters. ($i,$j,$k)