Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP4 Objects in $_SESSION

Status
Not open for further replies.

Itshim

Programmer
Apr 6, 2004
277
US
I am creating an application which requires three standard objects on every page load, once the user is logged in. Since I know these three objects are required for every page, I have decided to store them in the $_SESSION array, in hopes of cutting down the overhead of creating new objects every time a page loads.

I am aware of the one gotcha explained in this thread: thread434-685282 (class definitions must be parsed before calling session_start() ), this is not a problem. To complicate my question more, I also have a class acting as a wrapper for the session functions. So if I set a session variable, or need to get the variable the code looks similar to this:
Code:
$session->setValue('user_object', $user);

$user = $session->getValue('user_object');
Now I want to use pass by referencing so that if a change occurs in the $user object, it will also change in the $_SESSION array, like so:
Code:
class session 
{
    function setValue($name, &$value)
    {
        $_SESSION[$name] = $value;
    }

    function &getValue($name)
    {
        return $_SESSION[$name];
    }
}

$session = new session();
$user    = &$session->getValue('user_object');

I have tested this and it seems to work perfectly, I am just wondering if there are any issues that I am unaware of.

Thanks,
Itshim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top