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).
I have posted my answer on a similar question, posting it again 'cause it answers this one as well.
PHP serializes its sessions using the built-in serialize
and unserialize
methods. serialize
of PHP has the ability to serialize PHP objects (aka class instances) and convert them to string. When you unserialize
those strings, It converts them back those same classes with those values. Classes who have some private properties and want to encode/decode that or do something complex in their serialization/deserialization implement the Serializable
class and add serialize
and unserialize
methods to the class.
When PHP's unserialize
tries to unserialize a class object, but the class name isn't declared/required, instead of giving a warning or throwing an Exception
, it converts it to an object of __PHP_Incomplete_Class
.
If you don't want your session objects to convert to __PHP_Incomplete_Class
, You can do it by either requiring the class files before you invoke session_start
, or by registering an autoload function.
When you session_start()
in php $_SESSION
array is populated with corresponding objects. This means that all interfaces must be available (require). If the session has already been started previously by another script (eg framework) that had no visibility on the interfaces, objects in $ _SESSION
will be incomplete, and do it again session_start()
is useless because the session has already been started. One possible solution is to use the method session_write_close()
, then session_start()
which starts again populate $_SESSION
, but with visibility into interface, so your object in $_SESSION
will be good.