Store object in $_SESSION

Permalink
Hello, I need to store an object in the user's php session, the problem is PHP needs to know the class of the object before calling session_start().

What I've done is to manually include my library before c5 includes the startup/session.php script, however this solution is not elegant at all.

Is there a more elegant solution for this? I've already tried closing the session, including the library and reopening the session but the problem remains. This is how I've done this (taken from User::regenerateSession):

//close the session
unset($_SESSION['dashboardMenus']);
$tmpSession = $_SESSION;
session_write_close();

Loader::library("mylib");

//reopen the session
@setcookie(session_name(), session_id(), time()-100000);
@session_id(sha1(mt_rand()));
@session_start();
$_SESSION = $tmpSession;


Thanks in advance.