Re: Re: Question about superglobals
| From: | Carl P. Corliss | Date: | Sat, 17 Nov 2007 06:05:17 +0000 |
| Subject: | Re: Re: Question about superglobals | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33206@lists.php.net to get a copy of this message | ||
Sam Barrow wrote:
Thanks everyone, I knew this, but I didn't want to use runkit because it is a beta, and i don't want all that other stuff, just superglobals. Also, runkit only allows you to use php.ini, but my patch allows you to specify superglobals in your script with the keyword "superglobal" by saying: superglobal $var1, $var2 ;I don't get why you can't just use a Registry pattern here. Having a simpleRegistry object that you can throw data into and pull out of not only allows you to keep your global space clean, but allows you to encapsulate your "global" data and access it via a simple interface. Sure, it might be a few extra keystrokes to type something akin to: Registry::get('var1'); but, personally, I think the trade-off is well worth it. simple example class: -------------------- class Registry {
protect function __construct() {} // no instantiation - static class
static protected $data = array();
static public function get($name) {
return (isset(self::$data[$name]) ? self::$data[$name] : null);
}
static public function set($name, value) {
self::$data[$name] = $value;
}
}
--------------------
summary: why "fix" what ain't really broke...?
Cheers!,
--
Carl