Here's my code:

if(!isset($_SESSION['tree'])) {
$_SESSION['tree'] = new DBTree();
}
echo $_SESSION['tree']->sizeOf();

If the session variable isn't set, then it gets set and the echo works fine. But let's say I refresh the page, so the session variable is already set, so it skips the if statement, but the echo statement fails with error: "The script tried to execute a method or access a property of an incomplete object." Any help?