Edit report at https://bugs.php.net/bug.php?id=36696&edit=1
ID: 36696 Comment by: info at djdb dot be Reported by: iain at iaindooley dot com Summary: __destruct() is called before serialize() when object stored in session Status: Assigned Type: Feature/Change Request Package: Scripting Engine problem Operating System: * PHP Version: * Assigned To: sas Block user comment: N Private report: N New Comment: /** * @param mixed $user * @return void */ function setsessionuser($user){ $_SESSION['user']=serialize($user); } /** * getsessionuser() * @return object User */ function getsessionuser(){ return(isset($_SESSION['user']))?unserialize($_SESSION['user']):null; } class User extends User_data{ test and remake Previous Comments: ------------------------------------------------------------------------ [2013-06-27 22:20:01] yohg...@php.net There is exact dup bug report, but I cannot find. Workaround is call before session_write_close() before shutdown, but __destruct should be the last magicmethod to be called, isn't it? ------------------------------------------------------------------------ [2008-06-26 09:38:09] margus dot sipria at gmail dot com duplicate with a bug http://bugs.php.net/bug.php?id=33772 ------------------------------------------------------------------------ [2006-03-23 00:27:58] iain at iaindooley dot com in a garbage collection system, the destructor shouldn't be called on an object until the last reference to it is destroyed. if i do: $_SESSION['var'] = new Var(); then a reference to that object that was created should be stored in the $_SESSION array, and __destruct() should not be called until the $_SESSION array is destoryed. so clearly the session array must be being destroyed before the objects within it are serialized, which isn't right. ------------------------------------------------------------------------ [2006-03-22 18:13:41] il...@php.net There is nothing wrong with the order here. Temp var gets destroyed as soon as it is created, while session serialization happens at the end of the script. ------------------------------------------------------------------------ [2006-03-21 23:34:59] iain at iaindooley dot com i would say that the fact the order of operations changes for a temp var or an assigned var is a bug. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=36696 -- Edit this bug report at https://bugs.php.net/bug.php?id=36696&edit=1