php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30536 Can't write to $_SESSION in the __destructor()
Submitted: 2004-10-22 21:51 UTC Modified: 2004-10-22 22:00 UTC
From: deyv at php dot pl Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.0.2 OS: windows + linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: deyv at php dot pl
New email:
PHP Version: OS:

 

 [2004-10-22 21:51 UTC] deyv at php dot pl
Description:
------------
In the __destructor all changes in the 
$_SESSION array was not saved.


In the php 5.1 it's work corectly. 

Reproduce code:
---------------
session_start();

class test
{
 	function __construct()
 	{
        echo '<br />__construct <br />'; 	
 		var_dump( $_SESSION );
 		
 		if( empty( $_SESSION['iForConstruct'] ) ) 
 		{ 			
 			$_SESSION['iForConstruct'] = 1;
 			$_SESSION['iForDestruct']  = 1;
 		}
 		$_SESSION['iForConstruct']++;
 	}
 	 	
 	function __destruct()
 	{
 		echo '<br />__destruct'; 		
 		$_SESSION['iForDestruct'] ++;  	
 	}	
}
$test = new test();

Expected result:
----------------
In the all refresh we expect incrementing the values of $_SESSION['iForConstruct'] and $_SESSION['iForDestruct']
for all refresh's

Actual result:
--------------
incrementing only $_SESSION['iForConstruct']

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-22 22:00 UTC] derick@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

The session is ended before destructors are run.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 09:01:33 2025 UTC