Storing objects in sessions recursively

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PHP List,

I have a class called "Session", which creates an object stored in the $_SESSION variable. That object in turn holds on to a "User" object which keeps track of the activity of the individual user who has logged in and is using the web site. Then the $user object in turn holds on to an "Article" object, which keeps information about web content that the user is editing, previewing, and viewing.

The problem is that the "article" object keeps getting lost as the user clicks from page to page.

I'm hoping someone can explain to me why this might be happening.

As far as I can understand it, an object is basically just an array, and an object that "owns" an object as a member variable is just like storing an array in an array. I can't see any reason why there would be any limit to how many levels one could go down.

So I'm assuming there's no restriction on how many levels of objects owning objects there can be.

As for the code itself, I hope I don't strip out any key details, as it's all spread out across many classes. But here's what the basics of it look like:

In the User class, I have this method:

public function setCurrentArticle($currentArticle)
{
$this->currentArticle = $currentArticle;
}

In the Article class I have this line:

Session::getSession()->getUser()->setCurrentArticle($this);

In the Session class I have:

private static $session;
private $user;

public function __construct()
{
$this->user = new User();
}

public function getUser()
{
return $this->user;
}

public static function getSession()
{
if (!isset($_SESSION['session']))
{
$_SESSION['session'] = new Session();
}
return $_SESSION['session'];
}

I may have missed a detail in trying to keep this brief and readable. If so, please let me know and I will try to provide it.

Thank you for any advice.

--
Dave M G
Ubuntu 6.06 LTS
Kernel 2.6.17.7
Pentium D Dual Core Processor
PHP 5, MySQL 5, Apache 2

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux