Scopes and Data Types: CMSC 124
Scopes and Data Types: CMSC 124
CMSC 124
Scope
• Global scope
• Global variables are variables declared outside the
functions
– In C, declaration outside the function uses extern ie.,
extern int sum
– In PHP, globals can be accessed thru the $GLOBAL
array or no local variable must have the same name
Static Scope
• Global scope in PHP
$day = "Monday";
Interpretation of this code produces the
$month = "January"; following:
function calendar() { local day is Tuesday
$day = "Tuesday"; global day is Monday
global $month; global month is January
print "local day is $day <br />";
$gday = $GLOBALS['day'];
print "global day is $gday <br \>";
print "global month is $month <br />";
}
calendar();
Dynamic Scope