|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42567 Iterate over $_SESSION won't allow to unset its fields
Submitted: 2007-09-05 15:39 UTC Modified: 2007-09-14 01:00 UTC
From: gustavoa at gmail dot com Assigned:
Status: No Feedback Package: Session related
PHP Version: 5.2.4 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gustavoa at gmail dot com
New email:
PHP Version: OS:


 [2007-09-05 15:39 UTC] gustavoa at gmail dot com
The following session is stored in my temp directory:


I try to iterate over the $_SESSION var (using foreach) to unset some session keys, in particular those who start with "old_" (see the attached code). But I can't.

Besides, if after this iteration I try to modify the $_SESSION var nothing happens.

I'm using IIS 5.1 (blame my boss).

Reproduce code:

$prefix = 'old_';
foreach ($_SESSION as $key => $value) {
	if (substr($key, 0, 4) == $prefix) {
$_SESSION['var1'] = 'foo';

Expected result:
This change in the session file:


Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-06 10:43 UTC]
Please read:

There you find this: 
"As of PHP 5, you can easily modify array's elements by preceding $value with &."

So this should work:

foreach ($_SESSION as $key => &$value) {

 [2007-09-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Apr 01 08:03:37 2023 UTC