Re: Re: Includes vs. Functions

From: Date: Thu, 18 Jul 2002 23:42:58 +0000
Subject: Re: Re: Includes vs. Functions
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-108352@lists.php.net to get a copy of this message
On Thu, 18 Jul 2002 08:40:08 -0600, you wrote: See below... >At 09:20 PM 7/17/02 -0500, Michael Sims wrote: > >>$superglobals = array("var1", "var2", "var3", >>"var4", "var5", "..."); >> >>Now inside the function you can do this: >> >>function somefunction ($somevar) { >> >> global $superglobals; >> foreach($superglobals as $varname) { >> global $$varname; //resolves to $var1, $var2, $var3, etc. >> } >> >> //Other stuff here >> >>} > >You're working too hard! > >function somefunction( $somevar ) { > >global $suberglobals; > >extract( $superglobals ); > >//Other stuff here > >} Sorry, but your version is not functionally equivalent to mine. The call to extract() is creating locally scoped versions of those variables which do NOT reference the global versions. For proof, go here: http://mhs-dev.crye-leike.com/test.php Thanks for the pointer to extract() though, I had never used it before.

« previous php.general (#108352) next »