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]
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

  • 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


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.