Objects and sessions

From: Date: Thu, 09 Dec 2004 09:58:18 +0000
Subject: Objects and sessions
Groups: php.general 
Request: Send a blank email to php-general+get-203799@lists.php.net to get a copy of this message
Following code: <?php class SessionTestC { protected $value; function __construct ( $val ) {
       $this->value = $val;
} function GetValue () {
       return $this->value;
} } if ( isset ($_SESSION['TestObj'])) { echo 'Session Test is set to: '.$_SESSION['TestObj']->GetValue().'<br>'; } else { session_start (); echo 'Session Test was not set.<br>'; $_SESSION['TestObj'] = new SessionTestC ( 'This is a test' ); echo "<a href='".basename($_SERVER['PHP_SELF'])."'>Click here.</a><br>"; } ?> Gives me an error of incomplete object on second access, like this: *Fatal error*: main() [function.main <http://localhost/sfcms/Scripts/function.main>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "SessionTestC" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in */home/fmmarzoa/Develop/Stradivarius/Scripts/SessionTest.php* on line *16 *But as it can be seen, the class is defined in the script SessionTest.php itself, so... ??????

« previous php.general (#203799) next »