Re: quick globalisation?

From: Date: Tue, 24 Aug 2004 16:49:13 +0000
Subject: Re: quick globalisation?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-194597@lists.php.net to get a copy of this message
On Tue, 24 Aug 2004 12:21:03 +1000, Justin French <justin.french@indent.com.au> wrote: > Jay, > > "global $a, $b, $c" is used for bringing global variables INTO the > scope of the function... what I'm after is a way of making localised > variables (in function) available outside of the function. > > Justin > It also effectively makes the local variables global. As long as you do this *before* you use the vars, you're ok. Otherwise, you're going to have to use $GLOBALS. If you want a better way to do this, you could use object vars and then use get_object_vars, do a foreach, and put them in $GLOBALS. > > On 24/08/2004, at 1:38 AM, Jay Blanchard wrote: > > > [snip] > > Is there a quicker way to globalise something other than: > > > > $a = 'foo'; > > $b = 'bah'; > > ... > > $GLOBALS['a'] = $a; > > $GLOBALS['b'] = $b; > > > > ?? > > > > I was hoping for something like > > > > $a = 'foo'; > > $b = 'bah'; > > ... > > makeGlobal('a','b') /*or*/ makeGlobal($a,$b); > > [/snip] > > > > According to http://us3.php.net/language.variables.scope > > you could do > > something like > > > > global $a, $b, $c, ...; > > --- > Justin French > http://indent.com.au > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#194597) next »