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:
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:
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
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');
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