First look at the following code:
<?php
$var1 = "#####";
$var2 = "&&&&&";
function global_references($use_globals) {
global $var1, $var2;
if (!$use_globals) {
$var2 =&$var1; //1
} else {
$GLOBALS["var2"] =&$var1; //2
}
}
global_references(false);
echo "var2 is set to '$var2'<br/>";
global_references(true);
echo "var2 is set to '$var2'<br/>";
?>
The output results are as follows:
var2 is set to '&&&&&'
var2 is set to '#####'
It can be seen that in the above code:
$var2 =&$var1; //1
Only visible inside the function.
and
$GLOBALS["var2"] =&$var1; //2
Visible globally.