View Single Post
Old 06-08-2008, 01:52 PM   #4 (permalink)
xenon
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

It's not called renaming, it's simply a statement to help the parser understand what is the variable that needs to be modified (is it coming from the namespace or is it coming from the current function -- the latter is assumed by default).

PHP Code:
$a 5;

function 
showA()
{
    global 
$a// not renaming anything, just letting the parser know that the $a is declared globally, and use its value, instead of defining a function-level variable called $a

    
$a 10;
}

showA();
echo 
$a// will output 10, but if you remove the global statement (or comment it), it will output 5, of course 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
Dave (06-08-2008)