Jump to content

maintaining object state


ksmatthews

Recommended Posts

You can do it with session, but you still have to "re-create" it in a sense.

 

I cannot remember excatly how it is done, but I think it is something similiar to this:

 

<?php
session_start();
include('classdefinition.php'); // this is required.

if (!isset($_SESSION['object'])) {
    $object = new class();
}else {
    $object = unserialize($_SESSION['object']);
} 



// this needs to be at the end of the processing.
$_SESSION['object'] = serialize($object);
?>

 

I am not 100% sure if that is the correct code. I think I am missing something, but that is the basic gist of it. If I do some research and find out if that is right I will let you know.

 

EDIT:

Alright I remembered what I was missing, the serialize and unserialize functions. The above should work now.

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.