Page 1 of 1

*SOLVED*Sending Classes as $_SESSION variables

Posted: Tue Mar 09, 2004 12:18 pm
by Deemo
im working on something right now, and it requires me to send a class in between multiple pages. i would like to do this through Sessions. what i do in my index.php is:

Code: Select all

<?php
$User = new User;      //Declare new class
$User ->Import($INFO, $ID)    //Imports variables from database to $User
$_SESSION['User'] = $User
?>
this works, as if i go to my next page that uses the User class, if i type in

Code: Select all

<?php
echo $_SESSION['User'];
?>
if will return Object, so it IS being passed. but when i do something like

Code: Select all

<?php
echo $_SESSION['User'] ->ID;   //Echo part of class
?>
it returns the following error:
Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition user of the object you are trying to operate on was loaded _before_ the session was started in /var/www/html/SciFi/shop.php on line 69
what am i doing wrong??

Posted: Tue Mar 09, 2004 1:50 pm
by markl999
You need to include the file that has the class definition before using it via a session.
Eg

Code: Select all

<?php
require_once 'someclass.php';
session_start();
echo $_SESSION['User'] ->ID;
?>
Without the require_once you'll get that error you see.

Posted: Tue Mar 09, 2004 1:55 pm
by Deemo
thank you thank you thank you thank you :)