Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33364 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45527 invoked by uid 1010); 20 Nov 2007 22:08:02 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 45491 invoked from network); 20 Nov 2007 22:08:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Nov 2007 22:08:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.62.56 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.62.56 qmta06.westchester.pa.mail.comcast.net Received: from [76.96.62.56] ([76.96.62.56:39649] helo=QMTA06.westchester.pa.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/4B-22278-F4553474 for ; Tue, 20 Nov 2007 16:44:48 -0500 Received: from OMTA12.westchester.pa.mail.comcast.net ([76.96.62.44]) by QMTA06.westchester.pa.mail.comcast.net with comcast id F9bY1Y0010xGWP80501X00; Tue, 20 Nov 2007 21:44:45 +0000 Received: from earth.ufp ([71.228.13.89]) by OMTA12.westchester.pa.mail.comcast.net with comcast id F9kk1Y00Q1vH2xB0300000; Tue, 20 Nov 2007 21:44:45 +0000 X-Authority-Analysis: v=1.0 c=1 a=tJZsWP4XKNgA:10 a=OfHUBPiSNNGkxhyLjk0A:9 a=KIoZSRrZapZvvzSwufwA:7 a=8Fmz-6nnahTHGMGSIRHR6c-CTS8A:4 a=FHBbIDN7CdwA:10 a=jgFIvOWqR8MA:10 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id EF270D8307 for ; Sat, 17 Nov 2007 01:08:03 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F22i2i6T6bQG for ; Sat, 17 Nov 2007 01:08:03 -0600 (CST) Received: from vulcan.ufp (vulcan.ufp [192.168.42.4]) by earth.ufp (Postfix) with ESMTP id A5DF1D8231 for ; Sat, 17 Nov 2007 01:07:53 -0600 (CST) To: internals@lists.php.net Date: Sat, 17 Nov 2007 01:08:28 -0600 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) References: <8D.46.01128.768AD374@pb1.pair.com> <1195279864.12249.51.camel@sams-room> In-Reply-To: <1195279864.12249.51.camel@sams-room> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200711170108.28449.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Re: Question about superglobals From: larry@garfieldtech.com (Larry Garfield) Off the cuff, may have a bug or two, but you get the idea: function get_config() { static $config; if (empty($config)) { // Something to load the configuration here. } $params = func_get_args(); $return = $config; foreach ($params as $param) { if (isset($return[$param]) { $return = $return[$param]; } else { trigger_error(...); } } return $return; } $bob = get_config('thing', 'silly', 'bob'); No, not as fast as global $config;, but more self-documenting and therefore easier to maintain and the difference is smaller than the cost of one SQL query. Human cycles cost more than CPU cycles. On Saturday 17 November 2007, Sam Barrow wrote: > Not a bad idea, however in my case (don't know about others) I have very > deep arrays i use for my configuration. This would be more of a pain to > use with these get and set functions. Also, the performance would > probably be worse than just directly accessing the variable. > > Good point about not fixing what's not broken, but I think in this > context it couldn't hurt to fix it. I have already fixed it, my patch is > already written and I will continue testing it but I haven't come across > any problems using it. > > On Sat, 2007-11-17 at 01:05 -0500, Carl P. Corliss wrote: > > 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 -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson