Page 1 of 1
My Own SuperGlobal?
Posted: Fri Mar 10, 2006 11:46 am
by llfitness
I'm coding an ecommerce package and I have an array, $store_info, that I use EVERYWHERE. I'm tired of declaring it to be global, and there aren't any associated functions so there's no use in creating an object for it.
Is there a command I can use to promote this variable to a superglobal like $_SESSION or $_REQUEST?
jw
Posted: Fri Mar 10, 2006 11:50 am
by feyd
nope.
However you can call it via $GLOBALS['store_info'].
Posted: Fri Mar 10, 2006 11:56 am
by hawleyjr
Or you can set it as a session var...
Posted: Fri Mar 10, 2006 12:29 pm
by Chris Corbyn
Why not try something like this include at the top of each page?
Code: Select all
<?php
session_start();
$your_global =& $_SESSION['your_stuff'];
?>
Now you can just work with $your_global tansparently in the same way you'd be working with the $_SERVER superglobal.
I could put it in the session area
Posted: Fri Mar 10, 2006 12:45 pm
by llfitness
I guess, whether with good reason or not, I've always tried to keep my session variables as un-cluttered (read: small / limited) as possible. Is this such a fast operation in PHP that I shouldn't worry about it?
Posted: Fri Mar 10, 2006 12:47 pm
by feyd
the only real performance hit with sessions is unserialization, extraction and storage. Once it's in PHP, it doesn't matter much, it's just a variable.
and?
Posted: Fri Mar 10, 2006 12:49 pm
by llfitness
Right, so what does that cost? Is it astoundingly fast, average, or burdensome?
Posted: Fri Mar 10, 2006 12:53 pm
by feyd
it's minimal on most servers.
Posted: Fri Mar 10, 2006 12:57 pm
by Chris Corbyn
Sessions are used everywhere... they're nothing fancy. OK, if you're digging an old session back up fro the database or filesystem then there will be some overhead there but that's a one-off. You should see some of the session stuff we have on our pages at work

.