Re: object persistence within a session

From: Date: Fri, 07 Nov 2008 14:39:05 +0000
Subject: Re: object persistence within a session
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-283074@lists.php.net to get a copy of this message
On Fri, Nov 7, 2008 at 8:33 AM, Stan <stanleytberry@gmail.com> wrote: > If this is the wrong forum, please point me at the correct forum. > > I am new to PHP but have 40 years experience programming. > > My initial effort includes a class definition which needs to persist for the duration of a WWW > session. The code (this snippet is the beginning of Default.php) > > <?PHP > session_start(); > require_once 'CSSFrames_Includes/Classes.inc'; > if (!isset($_SESSION["navigator"])) > { > $_SESSION["navigator"] = new CSSFrames_Navigator; > } > else > { > parse_str($_SERVER['QUERY_STRING'], $queryString); > foreach ($queryString as $key => $value) > { > switch($key) > { > case "ID": > $_SESSION["navigator"]->set_page_ID($value); > break; > default: > break; > } > } > } > initially works ... $_session["navigator"] does exist and methods do function > correctly. When, however, I click a link and cause the script (Default.php) to be reentered, I get > the following > > Fatal error: main() [<a href='function.main'>function.main</a>]: The > script tried to execute a method or access a property of an incomplete object. Please ensure that > the class definition &quot;MyClass_defined&quot; 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 /MyWebSite.com/Default.php on line 16 > > which I understand to mean that my class definition (file?) has not been loaded. What I do not > understand is why has not the class definition been loaded? Did storing the object reference not > also store the class definition? What must I do to retain the class definition as part of the > session data? > > Thanks, > Stan Look into http://us.php.net/manual/en/function.spl-autoload-register.php

« previous php.general (#283074) next »