#36696 [Bgs->Opn]: __destruct() is called before serialize() when object stored in session

From: Date: Wed, 22 Mar 2006 23:28:01 +0000
Subject: #36696 [Bgs->Opn]: __destruct() is called before serialize() when object stored in session
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-94787@lists.php.net to get a copy of this message
 ID:               36696
 User updated by:  iain at iaindooley dot com
 Reported By:      iain at iaindooley dot com
-Status:           Bogus
+Status:           Open
 Bug Type:         Session related
 Operating System: *
 PHP Version:      5.1.2
 Assigned To:      sas
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2006-03-22 18:13:41] iliaa@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.

------------------------------------------------------------------------

[2006-03-21 15:47:16] iliaa@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

When putting objects into session or serializing them manually put the
instantiation result into a variable 1st and then use it.

Ex. $a = new Object();
$_SESSION['obj'] = $a;

Doing so avoids temp var, which gets destroyed right away hence leading
to the wrong order of operations.

------------------------------------------------------------------------

[2006-03-20 23:25:16] tony2001@php.net

Assigned to the maintainer.

------------------------------------------------------------------------

[2006-03-13 19:54:55] helly@php.net

exactly

------------------------------------------------------------------------

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
    http://bugs.php.net/36696

-- 
Edit this bug report at http://bugs.php.net/?id=36696&edit=1


Thread (15 messages)

« previous php.bugs (#94787) next »