Reputation: 213
I'm working on a generic UCP, and I'm trying to store a user profile object within a session. The problem standing, is that I can't grab any data from it.
A few snippets,
user.php
public $data, $logs;
public $user_name;
function User($user_name) {
this->user_name=$user_name;
this->Fetch(); //CAN_USE_FETCH_FOR_UPDATES
}
function Fetch() {
this->data=*; //SQL_DATA
this->logs=*; //SQL_DATA
}
functions.php
function create_user($user_name) {
require_once('./struct/user.php');
$user = new User($user_name);
$_SESSION['user'] = $user;
}
main.php
$user = $_SESSION['user'];
echo($user->user_name); //NOT_WORKING
echo($user->data['username']); //NOT_WORKING
I tried using print_r/var_dump on the session variable, and it prints the entire object. I just can't grab any data from it for whatever reason.
print_r($user)
(
[__PHP_Incomplete_Class_Name] => User
[data] => Array
(
[id] => 1
[username] => Veritas
...
Upvotes: 0
Views: 42
Reputation: 19214
The data retrieved from session isn't your object of class User
. It's a generic object, and property __PHP_Incomplete_Class_Name
suggests it should be instance of class User
but at the time object is created, PHP runtime does not know what User
class is. Try load User
class before you start session.
Upvotes: 1