note 111857 added to reserved.variables.globals
| From: | bkilinc at deyta dot net | Date: | Fri, 05 Apr 2013 09:21:07 +0000 |
| Subject: | note 111857 added to reserved.variables.globals | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194344@lists.php.net to get a copy of this message | ||
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();
----
Server IP: 69.147.83.199
Probable Submitter: 88.225.225.20
----
Manual Page -- http://php.net/manual/en/reserved.variables.globals.php
Edit -- https://master.php.net/note/edit/111857
Del: integrated -- https://master.php.net/note/delete/111857/integrated
Del: useless -- https://master.php.net/note/delete/111857/useless
Del: bad code -- https://master.php.net/note/delete/111857/bad+code
Del: spam -- https://master.php.net/note/delete/111857/spam
Del: non-english -- https://master.php.net/note/delete/111857/non-english
Del: in docs -- https://master.php.net/note/delete/111857/in+docs
Del: other reasons-- https://master.php.net/note/delete/111857
Reject -- https://master.php.net/note/reject/111857
Search -- https://master.php.net/manage/user-notes.php