ID: 27555
Updated by: [EMAIL PROTECTED]
Reported By: jaanus at heeringson dot com
Status: Open
-Bug Type: Session related
+Bug Type: Documentation problem
Operating System: Linux 2.4.24
PHP Version: 5CVS-2004-03-10 (dev)
New Comment:
Destructors are run (when not unset-ing yourself) after the session
module finalizes the session so everything done in constructors has no
effect. I agree it's not optimal behavior, but I don't think we need to
classify it as a bug. It is not documented though so I'm making this a
documentation problem.
Previous Comments:
------------------------------------------------------------------------
[2004-03-11 02:35:15] jaanus at heeringson dot com
Yes, but that is not the issue here, is it? What this bug is about is
the unability to add session variables from __destruct(). Obviously you
have to reload the page to se the effect on the real session. The
[destructor] => Yes will NEVER appear in $_SESSION.
------------------------------------------------------------------------
[2004-03-10 19:50:59] [EMAIL PROTECTED]
If you put something like "echo 'this happens now';" line in the
__destruct() call you will see that it's executed AFTER your print_r()
line. This is correct behaviour.
------------------------------------------------------------------------
[2004-03-10 18:42:06] jaanus at heeringson dot com
Description:
------------
Unable to add session variables from the __destruct() handler in a
class. The $_SESSION variable can be accessed and viewed in the
__destruct() handler though.
Reproduce code:
---------------
<pre>
<?php
session_start();
class test{
public function __destruct(){
$_SESSION['destructor']='Yes';
}
}
$class=new test();
if(empty($_SESSION['working'])) {
$_SESSION['working']='Yes';
print("New session?\n");
}
print_r($_SESSION);
?>
</pre>
Expected result:
----------------
Array
(
[destructor] => Yes
[working] => Yes
)
Actual result:
--------------
Array
(
[working] => Yes
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27555&edit=1