Possible duplicate:
Sample registry design ... good or bad?
I am working on a script game that uses PHP and approaches it in the same way as I create many of my sites. I have the habit of declaring one variable, which is stdClass, which contains many other variables that are important for execution. Then, if I ever need something inside the function (if it is not passed in the parameters), I just use the global variable $, in this case $ ar.
$ar = new stdClass; $ar->i = new stdClass; $ar->s = new stdClass; $ar->i->root = "/home/user"; $ar->i->logs = "{$ar->i->root}/logs"; $ar->i->bl = "{$ar->i->root}/customize/settings/bannedaccounts.txt"; $ar->i->sl = "{$ar->i->root}/customize/settings/silencedaccounts.txt"; $ar->s->points = array(10, 7, 5, 4, 3, 2, 1, 1, 1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1);
So, if I used one of the above variables in a function, I would approach it like this.
public function run() { global $ar;
Anyone advise not to do this? Does a single variable use and include many functions that should be avoided? I know that it is advisable to create functions that work only with the specified parameters, but I ask about this in terms of PHP performance and not programming clarity. Thanks!