note 111857 deleted from reserved.variables.globals by peehaa

From: Date: Thu, 09 Mar 2017 09:14:42 +0000
Subject: note 111857 deleted from reserved.variables.globals by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208881@lists.php.net to get a copy of this message
Note Submitter: bkilinc at deyta dot net ---- 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();

« previous php.notes (#208881) next »