Friday, January 01, 2010
serialize/unserialize php API - an observation
On first request, I was saving the object into session.
On second request, I retrieve the object from session for re-use.
I realized that on second request, the class Users_Model definition
is not available on the page load and unserialize API is not working as expected.
$_SESSION values are saved using serialize API (as session.save_handler was set to files)
On making the class definition available before session_start() call,
the $retrieveUserInstance worked fine.
$userInstance = new Users_Model();Make sure the class Users_Model definition is available.
$_SESSION['__key'] = $userInstance;
On second request, I retrieve the object from session for re-use.
$retrievedUserInstance = $_SESSION['__key'];
object(__PHP_Incomplete_Class)[1]I noticed the $retrieveUserInstance object missed several methods!!
public '__PHP_Incomplete_Class_Name' => string 'Users_Model' (length=11)
private 'id' => string '1' (length=1)
// ...
I realized that on second request, the class Users_Model definition
is not available on the page load and unserialize API is not working as expected.
$_SESSION values are saved using serialize API (as session.save_handler was set to files)
On making the class definition available before session_start() call,
the $retrieveUserInstance worked fine.
object(Users_Model)[1]Hope it saves sometime for you.
private 'id' => string '1' (length=1)
// ...