|
Posted by ZeldorBlat on 09/28/24 11:41
afrinspray@gmail.com wrote:
> I have one session object:
> $_SESSION['session_object'] = new SessionObject(some values here);
>
>
> And inside the SessionObject class definition, I'm creating two other
> objects:
> class SessionObject {
> public function __construct(...) {
> ...
> $this->class1 = serialize(new Class1(...));
> ...
> }
> }
>
> Here's an example of a get function I'm using:
> public function &getClass1() {
> $unserialized_obj = unserialize($this->class1);
> return $unserialized_lock;
> }
>
>
> How can I set some values in Class1 and Class2 and have them carry from
> page to page? What am I missing? I think my references technique is
> kinda screwed up. Can I set values of objects inside objects in
> sessions?
>
> Thanks,
> Mike
You haven't really described any specific problem or error message, so
it's hard to say what the problem is. Here are my thoughts:
Get rid of the serialize/unserialize stuff. The session handler will
take care of this automatically so you don't need to worry about it.
The problem, however, is that you need to make sure PHP knows about the
class before the object is unserialized. To do this, disable
session.auto_start in php.ini (if it isn't already) and make sure that
the class is defined before calling session_start().
If you're using PHP5, I highly recommend the use of __autoload() to
make this process easier.
Navigation:
[Reply to this message]
|