My Own SuperGlobal?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
llfitness
Forum Newbie
Posts: 12
Joined: Mon Feb 20, 2006 3:28 pm

My Own SuperGlobal?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

nope.

However you can call it via $GLOBALS['store_info'].
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Or you can set it as a session var...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
llfitness
Forum Newbie
Posts: 12
Joined: Mon Feb 20, 2006 3:28 pm

I could put it in the session area

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
llfitness
Forum Newbie
Posts: 12
Joined: Mon Feb 20, 2006 3:28 pm

and?

Post by llfitness »

Right, so what does that cost? Is it astoundingly fast, average, or burdensome?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's minimal on most servers.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 8O.
Post Reply