Re: [PHP4BETA] Global Variable scope within functions

From: Date: Wed, 10 May 2000 18:45:42 +0000
Subject: Re: [PHP4BETA] Global Variable scope within functions
References: 1 2 3  Groups: php.version4 
Request: Send a blank email to php-version4+get-14776@lists.php.net to get a copy of this message
| > On 05/09/00 09:43:35 PM psg@cooldog.com wrote: | > | > >To the PHP4 developer gurus: | > > | > >Is there any undocumented feature that would make it possible to have a | > >function with ALL global variables in its scope? | > > | > >The equivalent to this: | > > | > >function foo { | > > for (reset($GLOBALS); $Gvn = key($GLOBALS); next($GLOBALS)) | > > global $$Gvn; | > > .... | > >} | > | > Try extract($GLOBALS). | > | > However, I would caution that this is usually a sign of a design that needs | > reworking. | | I have to politely disagree. HTTP is stateless, after all, and | interpreted (so that your entire PHP tree is not involved in every | use). If you follow "true" clean programming you shouldn't have any | global variables at all -- try that with PHP :-P. The global ones are there just for your ease! They could have implemented a function which would return the contents into a variable of your choice, say something like: $BLAH = get_http_variables (); # functions don't hurt the *clean* programming Which wouldn't have made PHP as much successful as it is now... (To them, ease of use is the top priority yes, its above the "efficiency factor" as well, according to Zeev). And straight-forward for beginners as well. And I agree that your logic needs reworking if you wish to import all global variables. I like Perl better in this regard though! You use 'my|local' for the variables which you want to be local to a scope. Enjoy! Faisal

« previous php.version4 (#14776) next »