Jump to content

[SOLVED] Is it possible to have an instance of a class in a session?


emehrkay

Recommended Posts

I have not tried it, but it should work. The only restriction is that the class definition must be present before the session_start() -
[quote]If you do turn on session.auto_start then you cannot put objects into your sessions since the class definition has to be loaded before starting the session in order to recreate the objects in your session. [/quote]
[quote author=effigy link=topic=121008.msg496925#msg496925 date=1167931541]
An example of this being used is found in [url=http://www.senzalimiti.sk/slgrid/]slGrid[/url]; I've been experimenting with it lately.
[/quote]

cool. i just looked through the code and it does exactly what i was thinking about.
  • 2 weeks later...
I added solved too soon. It does not work

if i do
$_SESSION['dbc'] = new dbOjbect(); //that should set my database connection once and store the class as a session var

but when i go to do $_SESSION['dbc']->runQuery($query);

i get this crazy error

Fatal error: userSQL::login() [<a href='function.userSQL-login'>function.userSQL-login</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;dbObject&quot; of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /homepages/sql.php on line 27


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.