emehrkay Posted January 4, 2007 Share Posted January 4, 2007 Just something that crossed my mind.$_SESSION['class'] = new ClassName();and if I wanted to run a method from that session, could I do:$_SESSION['class']->method();?? Link to comment https://forums.phpfreaks.com/topic/32864-solved-is-it-possible-to-have-an-instance-of-a-class-in-a-session/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 4, 2007 Share Posted January 4, 2007 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 https://forums.phpfreaks.com/topic/32864-solved-is-it-possible-to-have-an-instance-of-a-class-in-a-session/#findComment-152994 Share on other sites More sharing options...
emehrkay Posted January 4, 2007 Author Share Posted January 4, 2007 Ill try it later. I didnt even think of that pf Link to comment https://forums.phpfreaks.com/topic/32864-solved-is-it-possible-to-have-an-instance-of-a-class-in-a-session/#findComment-153006 Share on other sites More sharing options...
effigy Posted January 4, 2007 Share Posted January 4, 2007 An example of this being used is found in [url=http://www.senzalimiti.sk/slgrid/]slGrid[/url]; I've been experimenting with it lately. Link to comment https://forums.phpfreaks.com/topic/32864-solved-is-it-possible-to-have-an-instance-of-a-class-in-a-session/#findComment-153008 Share on other sites More sharing options...
emehrkay Posted January 4, 2007 Author Share Posted January 4, 2007 [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 https://forums.phpfreaks.com/topic/32864-solved-is-it-possible-to-have-an-instance-of-a-class-in-a-session/#findComment-153014 Share on other sites More sharing options...
emehrkay Posted January 12, 2007 Author Share Posted January 12, 2007 I added solved too soon. It does not workif i do$_SESSION['dbc'] = new dbOjbect(); //that should set my database connection once and store the class as a session varbut when i go to do $_SESSION['dbc']->runQuery($query); i get this crazy errorFatal 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 "dbObject" 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 https://forums.phpfreaks.com/topic/32864-solved-is-it-possible-to-have-an-instance-of-a-class-in-a-session/#findComment-159439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.