Store the object itself in the session. To do so your object should implement __sleep() / __wakeup() functions.
Actually in this case you probably only need __wakeup()
. I'd do it something like that:
User class definition:
<?php //included file
class User {
private $user_id;
function getFromID($id) {... doing something; }
function __wakeup() {
$this->getFromID($this->user_id);
}
}
And then using it and retrieving/storing in session;
<?php //some page
$current_user = $_SESSION['user'];
if(!$current_user) $current_user = new User();
...
$_SESSION['user'] = $current_user;