Bug #17436 Updated: objects don't persist in sessions
| From: | twocandles3000 at hotmail dot com | Date: | Wed, 19 Jun 2002 09:44:50 +0000 |
| Subject: | Bug #17436 Updated: objects don't persist in sessions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-11361@lists.php.net to get a copy of this message | ||
ID: 17436
Updated by: twocandles3000@hotmail.com
Reported By: ndp@mac.com
Status: Critical
Bug Type: Session related
Operating System: MacOS X 10.1.4
PHP Version: 4.2.1
New Comment:
i suppose you have session auto_start disabled, don't you? since class
declaration must appear before unserializing an object, this code won't
work because of the unserialization occurs before the class declaration
if auto_start is set.
Previous Comments:
------------------------------------------------------------------------
[2002-06-01 12:32:06] markonen@php.net
Um, sorry, I reproduced a different bug. Sessions are not
working at all on my box. Looking into it.
------------------------------------------------------------------------
[2002-06-01 12:14:52] markonen@php.net
Reproduced here on OS X. mod_files can write the session
files ok, but doesn't seem to be able to read them. Digging
into this.
------------------------------------------------------------------------
[2002-05-26 13:49:25] ndp@mac.com
I have not been able to get objects to "come back to life"
since version 4.1. I have read (and understand) all the new
superglobals and security issues, and I am convinced it is
not that (although for a while I was blaming my
misunderstanding). The message php returns is that the
class is not defined-- but it is.
The following code shows the problem. You can see that
regular variables come back on the session page, but the
simple object just causes an error.
Here is the output:
------
Session variable set.
Session message made it: Variable made it.
Fatal error: The script tried to execute a method or access
a property of an incomplete object. Please ensure that the
class definition test_class of the object you are trying to
operate on was loaded _before_ the session was started in /
Users/ndp/Sites/php/session_test.php on line 27
-----
Here is the source code named session_test.php:
-----
<?
class test_class
{
var $m;
function test_class()
{
$this->m = "";
}
function set_m($in_m)
{
$this->m = $in_m;
}
function get_m()
{
return $this->m;
}
}
if (isset($_SESSION["m"]))
{
print "Session variable set.<br />";
print "Session message made it: ".$_SESSION["message"]."<
br />";
print "Value = ".$_SESSION["m"]->get_m()."<br />";
}
else
{
session_start();
$_SESSION["message"] = "Variable made it.";
$_SESSION["m"] = new test_class();
$_SESSION["m"]->set_m("YES");
}
?>
<form action=session_test.php method=get>
<input type=submit>
<form>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17436&edit=1