Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Persistent Object Problem...!! 1

Status
Not open for further replies.

FOR111

Programmer
Sep 29, 2005
103
MT
Hi all,

I was wondering how it is possible to keep an instance of an object between scripts!? what is usually done in this case!

Thanks

Nick
 
Hi jpadie..and thanks once again for your suggestions..

you mean that if i create a new class instance i can store that instance in a session variable:

$_SESSION['myUser'] = $clsUser;

Then to retrieve the class i would use:

$instanceUSer = $_SESSION['myUser'];
$instanceUSer->ID();

Is that correct?

Thanks for your input..much appreciated.

Nick
 
yup. can't see any reason why that wouldn't work.

of course - php needs to know about the class of the object before the session is started thus you cannot use session autostart.
 
Hi jpadie once again...

i'm getting this error now:

Code:
Fatal error: GUI_LOGIN_USER() [<a href='function.GUI-LOGIN-USER'>function.GUI-LOGIN-USER</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;clsEncryptSystem&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 /IntranetStandard/admin/bin/functions/_user_functions.php on line 25

Thanks for any help in providing answers..

Nick
 
that's what i said above.
you must include the class before you start the session.

Code:
require "classdefinition.php";
session_start();

otherwise php does not know how to unserialise the object.
 
The problem is that the server has already have the auto_start enabled within the php.ini. I tried this init_set('auto_start', '0') at the beginning but its not helping much! is there another way to tackle this problem?

Thanks
 
yes. turn off auto_start in the php.ini file.
the alternative is to serialise the object yourself and then store the serialised string in a session element.

you can then unserialise the string programmatically (but not automatically) after you have declared the class.

Code:
$_SESSION['myUser'] = serialize ($instanceUSer);

and in reverse
Code:
require_once ("classdefinition.php");
$instanceUSer = unserialize($_SESSION['myUser']);
 
Hi again,

unfortuntely we're still in the same place;

i turned off auto_start and re-written the script as shown above. though now its saying that the object does not exist!

Thanks
 
if you have turned off autostart then go back to the original script, which is neater anyway!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top