I prefer accessing globals through static function calls. Source code looks better; I use glb::get('myglobalvar') instead of $GLOBALS['myglobalvar']. This gives me full control over global access, which can be the source of problems in practice.
class glb
{
static public function set($name, $value)
{
$GLOBALS[$name] = $value;
}
static public function get($name)
{
return $GLOBALS[$name];
}
}
$myglobalvar = 'Hello, World !';
function myfunction()
{
$val = glb::get('myglobalvar');
echo "$val\n";
glb::set('myglobalvar', 'hi, again :)');
$val = glb::get('myglobalvar');
echo "$val\n";
}
myfunction();