Re: $_SESSION saves all values but Class -- works on one server butnot another?! [SOLVED]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



UGH!!!!

After a WEEK of wasted time, I finally tracked this down. 

If you have a __destructor() on a class object that you're saving in a
$_SESSION, then that object will have all it's values NULL'd out when you
call session_start() and retrieve it.

http://www.php.net/session-set-save-handler

"Write and Close handlers are called AFTER destructing objects since PHP
5.0.5. Thus destructors can use sessions but session handler can't use
objects. In prior versions, they were called in the opposite order. It is
possible to call session_write_close() from the destructor to solve this
chicken and egg problem. "

Why wouldn't you save the session values out BEFORE destroying them? Why
should the programmer be burdened with this crap? It worked just fine in
prior versions and now it's broken in my opinion.

So you have to do something like this now:

	function __destruct() 
	{
		session_write_close();

		foreach($this as $key => $value) 
			unset($this->$key);
	}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux