|
Posted by JDS on 08/23/05 22:56
On Tue, 23 Aug 2005 12:01:04 -0700, Super Mango wrote:
> Hi -
>
> Is it possible to change the status of a variable to superglobal so
> it'll be valid inside functions without declaring it with "global"
> inside each function?
>
> Thanks -
All you have to do is put it inside one of the superglobal arrays. Use
those arrays directly inside the function.
e.g. instead of
function donut(){
global $holes;
return $holes - 1;
}
do
function donut(){
return $GLOBALS['holes'] - 1;
/* or $_SESSION['holes'] or $_POST['holes'] or other superglobal */
}
However, the real answer to your question is DO NOT USE GLOBALS INSIDE
FUNCTIONS!!!! You are just asking for trouble down the line, take my word
for it.
--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
Navigation:
[Reply to this message]
|