Edit report at https://bugs.php.net/bug.php?id=26099&edit=1
ID: 26099 Updated by: yohg...@php.net Reported by: nospam0 at malkusch dot de Summary: session is not available in __destruct() -Status: Open +Status: Closed Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: Linux PHP Version: 5.0.0b2 (beta2) -Assigned To: +Assigned To: yohgaki Block user comment: N Private report: N New Comment: I verified with following script. Session module is PHP_SESSION_NONE status after session_destroy(). <?php class Bug { private $i = 0; public function __construct() { session_start(); if ( isset( $_SESSION['i'] ) ) { $this->i = $_SESSION['i']; } $this->i ++; $_SESSION['i'] = $this->i; } public function printLink() { echo '<a href="/?' . SID . '">Bug</a>: ' . $this->i . PHP_EOL; } public function __destruct() { session_destroy(); echo 'destruct'.PHP_EOL; } } $bug1 = new Bug(); $bug2 = new Bug(); $bug1->printLink(); unset($bug1); var_dump(session_status()); Previous Comments: ------------------------------------------------------------------------ [2007-11-05 14:42:37] lokrain at gmail dot com I think you can still call session_destroy() or any other session functions using register_shutdown_function(). You even can work around that with hidden iframes, if you want to destroy a class before the main php end, but I think this is not the case you are looking for. ------------------------------------------------------------------------ [2003-11-03 15:53:16] nospam0 at malkusch dot de Description: ------------ Actually I'm talking about beta2 of PHP5, but it wasn't listed. I think the __destruct() method should do things like cleaning up any resources. So it would be nice if I could destroy Sessions which are empty. But the Session Handler for closing the Session is called before the __destruct() methods. Reproduce code: --------------- class Bug { private $i = 0; public function __construct() { session_start(); if ( isset( $_SESSION['i'] ) ) { $this->i = $_SESSION['i']; } $this->i ++; $_SESSION['i'] = $this->i; } public function printLink() { echo '<a href="/?' . SID . '">Bug</a>: ' . $this->i; } public function __destruct() { if ( $this->i > 4 ) { session_destroy(); } } } $bug = new Bug(); $bug->printLink(); Expected result: ---------------- I would expect that the Session is still active and can be manipulated in any __destruct() method. Actual result: -------------- PHP's Session Handler for closing the Session is called before any __destruct method. So I can't do anything with the Session in the __destruct method. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=26099&edit=1