Re: How to preserve instance of class within sessions ???
| From: | Jason Sheets | Date: | Thu, 08 May 2003 13:22:58 +0000 |
| Subject: | Re: How to preserve instance of class within sessions ??? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146835@lists.php.net to get a copy of this message | ||
You can serialize and unserialize the object in $_SESSION.
Jason
Andrei Verovski (aka MacGuru) wrote:
Hi, I have programmed in C++ before (with class libraries). I am always had global variable (instance of CApplication class) which carries application properties and data all the time program is running. When I have tried to use the same tactic in PHP, some curious difficulties arise. I have class CMyApp which stores a lot of app data (like persistent database connections via ADODB), and instance of this class called $gApp (of course, as global). I am using "register globals off" and trying to preserve $gApp through entire execution flow of the program. However, as I am understood from the manual, objects cannot be preserved via session SID data, neither the object is alive in $GLOBALS after header("Location: script.php") with SID (not shown there). As a dubious solution I can write two functions which extract object's fields into plain variables, put them into global scope, and then recreating object back from saved global data. However, this is kinda awkward. The questions is how to preserve instance of the class within sessions (if it is possible at all, of course) with "register globals off" (or at least, how to turn register globals on ONLY for my program, and not for any other php app). Thanks in advance for any suggestion. ********************************************* * Best Regards --- Andrei Verovski * * Personal Home Page * http://snow.prohosting.com/guru4mac * Mac, Linux, DTP, Development, IT WEB Site *********************************************