Page 1 of 1
I need to turn a variable to a super global
Posted: Tue Sep 27, 2005 5:29 am
by Mosab
Hi everybody,
I need to convert a variable into a super global one , without using cookies and sessions , is that possible?!
And if so , How ?!!
Thanks in advance ..
Posted: Tue Sep 27, 2005 5:57 am
by dbevfat
1) You can't.
2) It's a bad idea anyway, you should consider a different design.
3) If you really REALLY want to, you could do something like:
Code: Select all
$myvar =1234;
$GLOBALS['myvar'] = $myvar;
// in a different scope:
echo $GLOBALS['myvar'];
But, did you mean a global or a persistent variable?
Re: I need to turn a variable to a super global
Posted: Tue Sep 27, 2005 7:27 am
by Roja
Mosab wrote:Hi everybody,
I need to convert a variable into a super global one , without using cookies and sessions , is that possible?!
And if so , How ?!!
Thanks in advance ..
Sure its possible.
Code: Select all
$whatever = 'important variable to put in the super global area';
$_REQUEST['whatever'] = $whatever;
Done. Now its in the superglobal scope.
The bigger question is why you want that. More likely, you want global, not super-global. In that case, you'd do:
Code: Select all
global $whatever;
$whatever = 'important variable to put in the super global area';
And then code below it (except functions, which would need a similar global call) can 'see' that variable.
But again, its important to ask why you need it global. Your design probably needs more thought if you need more than a few globals.