Hi, your code my be this , you must use session_start() first: <?php session_start (); 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 { 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>"; }
?>
Francisco M. Marzoa Alonso wrote:
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... ??????
-- -- ShenKong (shenkong@xxxxxxx) -- http://www.openphp.cn
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php