Objects inside Sessions
| From: | William N. Zanatta | Date: | Mon, 26 May 2003 15:59:14 +0000 |
| Subject: | Objects inside Sessions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-148992@lists.php.net to get a copy of this message | ||
Hi,
I'm having a little problem when I put an object inside a session
variable.
I have the following code which brings me an object if it is set in
_SESSION or creates a new one if it is not set.
It is working almost fine except that sometimes it gives me the freak
message "Fatal error: Unknown(): The script tried to execute a method or
access a property of an incomplete object. Please ensure that the class
definition library of the object you are trying to operate on was
loaded _before_ the session was started in /xxx/.../.../.../file.php on
line 12".
The code:
<snip>
function coreNewObject($class, $arg = '') {
if(!isset($_SESSION['CORE_OBJECTS']))
$_SESSION['CORE_OBJECTS'] = array();
if(isset($_SESSION['CORE_OBJECTS'][$class])) {
$init = "{$class}Init";
if(method_exists($_SESSION['CORE_OBJECTS'][$class], $init))
$_SESSION['CORE_OBJECTS'][$class]->$init($arg);
return($_SESSION['CORE_OBJECTS'][$class]);
}
if(class_exists($class)) {
$_SESSION['CORE_OBJECTS'][$class] = new $class($arg);
return($_SESSION['CORE_OBJECTS'][$class]);
}
return(false);
</snip>
This happens in a page that contains...
<snip>
/* library class definition */
require_once("includes/library.class.php");
/* this initializes the session and do some other stuff */
Core::Core();
if($_REQUEST['clear'])
session_destroy();
$lib = Core::coreNewObject('Library');
/* the error occurs here! */
$lib->libSetCategoryReference();
</snip>
I find this behavior strange 'cos this only happens when I do a 'reload'
on the page. Normal navigation, through links and so, doesn't gives me any
errors.
Also, session.auto_start is not set.
What are the reasons why an object gets a "__PHP_Incomplete_Class"
status?
Any suggestions? You may contact me in PVT if you want..
I tried some archives digging but didn't find any lights...
Thanks,
William