Re: Protected Super Global Array

From: Date: Wed, 19 Dec 2007 14:05:55 +0000
Subject: Re: Protected Super Global Array
References: 1  Groups: php.evangelism 
Request: Send a blank email to php-evangelism+get-468@lists.php.net to get a copy of this message
Hello First of all thanks for response, and please mind English was not my mother language, I try to respond far I can command the english. Everyting begins with writing multi lingual pages. I start to use large language translation arrays. then I need them many of my functions. Then I realize I intizaling objects (like memcached or adodb) in so many location. Then I start to use $GLOBALS['db'] = new adodb; or $GLOBALS['lang']['eng']['hello_customer'] = 'Hello Customer'; $GLOBALS['lang']['tr']['hello_customer'] = 'Hosgeldin Musteri'; $GLOBALS['c']['lang'] = 'eng'; or someting like that. usage was so simple function foo() { $GLOBALS['db']->Execute($Sql); } or function bar() { echo "<div> ".$GLOBALS['lang'][$GLOBALS['c']['lang']] ['hello_customer']."</div>"; } From my point of view it much much easy to use and creates much less confusing code than using registry thing classes. Of course performance side was secondary benefit. User Created Protected super global variable may great addon to php for my kind of function based programmers. Yes I know in these days everthign for OO probably useless for OO paradigim and I belive this was helpfull for procedural style users. also I have no ability to code in c. Thats why I'm asking there thanks Sancar On Wednesday 19 December 2007 10:43:59 Pádraic Brady wrote: > Hi Sancar, > > I seriously doubt it's something we need in core. The best solution is > still an object oriented system like Zend_Registry or perhaps your own > homegrown ArrayAccess implementation from SPL. Globals really are > discouraged because they force objects to rely on an external resource > that's like weaving a spider's web across your code - no object can escape > for reuse elsewhere in another general system. Overusing Zend_Registry is > as bad as any global, so maybe if having global access is really necessary > you're better off just adding such an object/ArrayAccess to $_GLOBAL and > being honest about what it is :). > > The alternative is to write an extension yourself in C (argh!) which is > probably not what you want to get stuck with. > > Best regards, > Paddy > > Pádraic Brady > > http://blog.astrumfutura.com > http://www.patternsforphp.com > OpenID Europe Foundation Irish Representative > >

« previous php.evangelism (#468) next »