By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

How to add (or emulate) a new superglobal

P: n/a
This is just for curiosity, but:

Lets say I would like to have a new superglobal, in addition to
automatically made get, post, cookie and session.

I mean, I would (theoretically) want to AVOID doing

function ()
{
global $config;
....
}

and just be able to use $config in functions and classes.
Not that it would be the nicest practise though. But let's say for the sake
of fun or doing it.

Is there a way? Of course you could reset, set and reset again some session
variable, but that would not be very nice way.

Feb 7 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
P Pulkkinen wrote:
This is just for curiosity, but:

Lets say I would like to have a new superglobal, in addition to
automatically made get, post, cookie and session.

I mean, I would (theoretically) want to AVOID doing

function ()
{
global $config;
....
}

and just be able to use $config in functions and classes.
Not that it would be the nicest practise though. But let's say for the
sake of fun or doing it.

Is there a way? Of course you could reset, set and reset again some
session variable, but that would not be very nice way.
Why not simply throw your stuff in $GLOBALS?

Something like this:
$myVars = array('nr1' =123, 'nr2' ="bla");
$GLOBALS[] = $myVars;

It should have the same effect. I think.

Regards,
Erwin Moller
Feb 7 '07 #2

P: n/a
Why not simply throw your stuff in $GLOBALS?
Something like this:
$myVars = array('nr1' =123, 'nr2' ="bla");
$GLOBALS[] = $myVars;
It should have the same effect. I think.
Regards,
Erwin Moller
Well, I have not tried. I hope it works. I thought $GLOBALS, or was it
$_GLOBALS, was only reserved for php inner automatic use.
Feb 7 '07 #3

P: n/a
P Pulkkinen wrote:
>Why not simply throw your stuff in $GLOBALS?
Something like this:
$myVars = array('nr1' =123, 'nr2' ="bla");
$GLOBALS[] = $myVars;
It should have the same effect. I think.
Regards,
Erwin Moller

Well, I have not tried. I hope it works. I thought $GLOBALS, or was it
$_GLOBALS, was only reserved for php inner automatic use.
Yes, I asked in the very newsgroup a week ago how to throw out all variables
in PHP.
I tried print_r($_GLOBALS), but it turned out the developers named it in
their infinite wisdom $GLOBALS without the _.

Regards,
Erwin Moller
Feb 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.