From:             [EMAIL PROTECTED]
Operating system: MacOS X 10.1.4
PHP version:      4.2.1
PHP Bug Type:     Session related
Bug description:  objects don't persist in sessions

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 bug report at http://bugs.php.net/?id=17436&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=17436&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=17436&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=17436&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=17436&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17436&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=17436&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=17436&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=17436&r=submittedtwice
register_globals:    http://bugs.php.net/fix.php?id=17436&r=globals

Reply via email to