ksmatthews Posted January 7, 2009 Share Posted January 7, 2009 Hi There, I would like to load a page the first time to create an object of a class. When I reload that page I would like to change properties of that same object WITHOUT re-creating it. How is this possible ? Steven M Quote Link to comment https://forums.phpfreaks.com/topic/139887-maintaining-object-state/ Share on other sites More sharing options...
premiso Posted January 7, 2009 Share Posted January 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/139887-maintaining-object-state/#findComment-731861 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.