#27555 [Opn]: Unable to modify $_SESSION from __destruct()

From: Date: Thu, 11 Mar 2004 08:16:30 +0000
Subject: #27555 [Opn]: Unable to modify $_SESSION from __destruct()
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969359475@lists.php.net to get a copy of this message
ID: 27555 Updated by: derick@php.net 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] sniper@php.net 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

« previous php.doc (#969359475) next »