injh85 Posted December 16, 2007 Share Posted December 16, 2007 hi there i've 2 classes Person n Member (extends Person). i tried to pass a Member obj into the session. when i try to execute methods from the session i got this error Fatal error: Call to a member function getFullname() on a non-object in C:\wamp\www\katong\admin\admin_index.php on line 9 sample codes class Person { function getName() { return $this->name; } } class Member extends Person { function Member($a) { } function getLogin() { return $this->login; } } test1.php $_SESSION["Member"] = new Member($nric); test2.php $_SESSION['Member'] = serialize($loginPerson); $loginPerson = unserialize($_SESSION['Member']); echo $loginPerson->getName(); Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 16, 2007 Share Posted December 16, 2007 as far as i know you cont have to serialize to place thigns into an array Quote Link to comment Share on other sites More sharing options...
corbin Posted December 16, 2007 Share Posted December 16, 2007 C:\Users\Corbin>php -r "class Corbin { function Test() { echo 'hi';} }; $c = new Corbin; $l = serialize($c); $d = unserialize($l); $d->Test();" hi That works, so theoretically this should work: $m = new Member($nirc); $_SESSION['Member'] = serialize($m); //and later $m = unserialize($_SESSION['member']); $m->getName(); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 16, 2007 Share Posted December 16, 2007 This might help from the manual - 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. All registered variables are serialized after the request finishes. Registered variables which are undefined are marked as being not defined. On subsequent accesses, these are not defined by the session module unless the user defines them later. Warning Some types of data can not be serialized thus stored in sessions. It includes resource variables or objects with circular references (i.e. objects which passes a reference to itself to another object). If you are using objects, the class definition needs to be in program before the session start. Session data is already serialized, so doing it again won't solve the error. Objects with circular references cannot not be serialized and cannot be put into a session. Quote Link to comment 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.