Re: globalize all variables not coming from a certain form...

From: Date: Sat, 19 May 2001 19:54:02 +0000
Subject: Re: globalize all variables not coming from a certain form...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53546@lists.php.net to get a copy of this message
I hate using global variables this way in functions, but it can be done. <?php function test() { global $HTTP_POST_VARS; if ($HTTP_POST_VARS['form'] == 'func') foreach($HTTP_POST_VARS as $pos => $val) global $pos; // reset of your code. } ?> there are good reasons for global variables, but use them wisely, globals are offten missused and create illegible code. most variables should be passed as arguments to the function. -- Chris Lee lee@mediawaveonline.com "Siim Einfeldt aka Itpunk" <siim_e@pshg.edu.ee> wrote in message news:Pine.LNX.4.33.0105191233490.7806-100000@pshg.edu.ee... > > Hi everybody, > > Is it possible (and if it is, how) to globalize all the variables, that > come from some form, automatically? > For example: > > function do_something(){ > global $form; > if($form != "func"){ > /* globalize all the variables that come from a form > called $form . How to do it? */ > } > } > > Yes, I could it manually - global $firstname,$lastname,$addres, etc > etc...but the function is being used by different scripts and I need to > globalize only these variables that come from that particular form ... and > all that 'automatically'. > > Any ideas? > > Thanks, > Siim Einfeldt > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#53546) next »