#17436 [Ctl->Opn]: objects don't persist in sessions

From: Date: Mon, 16 Sep 2002 19:55:39 +0000
Subject: #17436 [Ctl->Opn]: objects don't persist in sessions
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-19490@lists.php.net to get a copy of this message
ID: 17436 Updated by: derick@php.net Reported By: ndp@mac.com -Status: Critical +Status: Open -Bug Type: Session related +Bug Type: Documentation problem Operating System: MacOS X 10.1.4 PHP Version: 4.2.1 New Comment: It should be documented that session autostart causes this problem (read latest posting by user). Derick Previous Comments: ------------------------------------------------------------------------ [2002-06-20 14:10:08] ndp@mac.com Yes, the issue is indeed session auto_start. (I put a comment in about this, but don't see it now.) My recommendation was that the error message could be changed to indicate what is going on, as this was pretty hard to track down. The upgrade came with a new php.ini file, and I trusted it-- therefore it seemed like the new version was broken, when it wasn't. The error message could be something like "session objects are not compatible with session_auto_start setting". That would help you fix the problem. I put notes where I could on the php.net site, but it seems like someone else will undoubtedly run into the same problem and have the same difficulty diagnosing it. Andy ------------------------------------------------------------------------ [2002-06-19 05:44:50] twocandles3000@hotmail.com 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#19490) next »