|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-11-03 15:53 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 04:00:01 2025 UTC |
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());