Re: Sessions in classes dosn't work!?

From: Date: Thu, 30 Aug 2001 12:25:35 +0000
Subject: Re: Sessions in classes dosn't work!?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-65253@lists.php.net to get a copy of this message
> Hmmm, it seems that "obj" is not saved to the session file. > > > I don't thik that & before new is needed. This is weird :) It worked when I removed the & (thought that I tried that ;). Now I just can't remember why I put it there in the first place. I hope it wasn't importent ... well I will proboply find out when some of the code dosn't work. > Also may the problem is in that you use the class contructor. When > objects are saved in session, and on other page you want to wakeup them > you must provide two methods for the class: > function __sleep(){ > return array("r","l","p","m_id"); > } > function __wakeup(){ > $this->res_id=mysql_connnect("user","pass","host"); > } > __sleep() (double under) is called before wrinting in session file. it > returns names (as strings) of variables which have to be saved. Why not > all, because you can have a $res_id of db_link which is meaningless to > save. __wakeup() is called when the object is restored in memory. If > you have $res_id you have to create it here, so the persistent object > after restoring to be as before saving. I knew about the __sleep() and __wakeup() but not about the returning of an array containing the names of the varibles that needs to be stored. Cool feature - Thanks for the tip :) /watson

« previous php.general (#65253) next »