Re: Global variables? (unset/set or what?)

From: Date: Sun, 20 May 2001 00:01:50 +0000
Subject: Re: Global variables? (unset/set or what?)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-53569@lists.php.net to get a copy of this message
In article <9e6s21$2rk$1@toye.p.sourceforge.net>, oblivion@lunamorena.net ("Richard") wrote: > So i should start the header (or wherever in the header) with : > > $GLOBALS["userPassword"] = "whatever"; > > function cp() { > global $userPassword; > > // $userPassword is 'whatever' // > } You're making an extra step. The variables stored in the $GLOBALS array don't have to be declared as global within a function. They're already available within the function. To make a global variable available within a function's local namespace, you _either_: * pass it by reference: function cp(&$userPassword) * declare it as a global: global $userPassword * make it an element of the $GLOBALS array: $GLOBALS['userPassword'] (You could also pass by value, but then you're dealing with a copy of the variable instead of the variable itself.) -- CC

« previous php.general (#53569) next »