faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 44 people (43%) answered Yes
Recently 5 of 10 people (50%) answered Yes


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)