From:             gustavoa at gmail dot com
Operating system: Windows
PHP version:      5.2.4
PHP Bug Type:     Session related
Bug description:  Iterate over $_SESSION won't allow to unset its fields

Description:
------------
The following session is stored in my temp directory:

old_var2|s:4:"foo2";

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:
---------------
session_start();

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

Expected result:
----------------
This change in the session file:

var1|s:3:"foo";

Actual result:
--------------
old_var2|s:4:"foo2";

-- 
Edit bug report at http://bugs.php.net/?id=42567&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42567&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42567&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42567&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42567&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42567&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42567&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42567&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42567&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42567&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42567&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42567&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42567&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42567&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42567&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42567&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42567&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42567&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42567&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42567&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42567&r=mysqlcfg

Reply via email to