assigning class object as a session variable HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

assigning class object as a session variable HELP!

Post by bg »

I'm trying to pass along a class object as a session variable, and I'm not having much luck.

basically I have

Code: Select all

include ('cClass.class.php');

session_start();
if (!empty($_SESSIONї'obj']){
unset($_SESSIONї'obj']);
}

$obj = new cClass('construct it');

$_SESSIONї'obj'] = $obj;
then in a seperate script

Code: Select all

include ('cClass.class.php');

$obj = new cClass(); //added this line because i was getting an error about instantizing a class object before its been defined or something

session_start();
$obj = $_SESSIONї'obj'];


echo $obj->get_something();
Basically, my code is acting like $obj is a class without any values assigned within it. Its like its brand spankin new. What am I doin wrong here?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

The code works fine for me (though i didn't need the $obj = new cClass(); that you have in the second script).
Do sessions in general work ok for you, or just this particular script?
Post Reply