PHP Session with an Incomplete Object
It's missing the serialize/unserialize of your template class.
Take a look here for an working example I gave on another question of yours.
For instance, you probably want this:
<?php
$_SESSION['template'] = serialize($template);
?>
and
<?php
$template = unserialize($_SESSION['template']);
?>
Edit:
reading your comment about moving it to the top gives one hint.
The automatic serialization/unserialization occurs when you call session_start()
.
That means the order in which you include your files and call the session_start()
is very important.
For example:
This would be wrong:
<?php
session_start();
include 'inc/template.class.php';
?>
While this would be correct:
<?php
include 'inc/template.class.php';
session_start();
?>
Now, I see in your example that it is in the CORRECT order, but I also notice you do many other includes before including template.class.php
Would it be possible that one of those includes (perhaps prep.php or header.class.php) does call start_session()
too?
If yes, that was your issue (session_start()
being called before your template.class.php).
__PHP_Incomplete_Class Object even though class is included before session started
To store an object in a session two things must happen:
1) The class must be defined before the session is started.
2) The class must implement serializable.
PHP - Session can't store classes?
You must ensure that the class definition is loaded before you session_start(), otherwise a default class (with no methods) is created instead.
Auto-loading classes wont work. Nor will loading class definitions AFTER session_start.
Incomplete PHP class when serializing object in sessions
In ZF's bootstrap, the session was started before autoloading.
/**
* Make XXX_* classes available
*/
protected function _initAutoloaders()
{
$loader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'XXX',
'basePath' => APPLICATION_PATH
));
}
public function _initSession()
{
$config = $this->_config->custom->session;
/**
* For other settings, see the link below:
* http://framework.zend.com/manual/en/zend.session.global_session_management.html
*/
$sessionOptions = array(
'name' => $config->name,
'gc_maxlifetime' => $config->ttl,
'use_only_cookies' => $config->onlyCookies,
// 'strict' => true,
// 'path' => '/',
);
// store session info in DB
$sessDbConfig = array(
'name' => 'xxx_session',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
Zend_Session::setOptions($sessionOptions);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($sessDbConfig));
Zend_Session::start();
}
When I was getting the errors I was talking about, the method declaration was the other way around: _initSession()
was first, then _initAutoloaders()
- and this was the exact order ZF was processing them.
I'll test some more, but this seems to work (and logical). Thanks for all your suggestions.
Related Topics
Illegal Command Error Code 127 in PHP Exec Function
Opposite of Nl2Br? Is It Str_Replace
Why Can't I Access the Array with Index Directly
How to Make Sure That Values from MySQL Keep Their Type in PHP
PHP Optional Parameters - Specify Parameter Value by Name
Submit Multiple Forms with One Button
PHP Undefined Index Error $_Files
Nested PHP Ternary Trouble: Ternary Output != If - Else
How to Download a File on Clicking the Name of File Using PHP
Sort a Set of Multidimensional Arrays by Array Elements
PHP Warning: Unknown: Failed to Open Stream
How to Test PHP Locally Without Installing a Server
Loop Through All Months in a Date Range
How to Perform Multiple Guzzle Requests at the Same Time
Why Does File_Get_Contents Work with Google.Com But Not with My Site