From:             mbechler at eenterphace dot org
Operating system: Any?
PHP version:      5.2.0
PHP Bug Type:     Session related
Bug description:  Unsetting a session var in a foreach loop over $_SESSION

Description:
------------
When 'register_long_arrays' is enabled and a session variable is unset
within a foreach loop over $_SESSION the session is not written out
anymore, causing the changes to the session beeing lost.
(session_unregister works nice btw.)

Reproduced on various (patched and vanilla) 5.* (including 5.2.0) versions
on GNU/Linux

Some debugging showed that actually the internal pointer (in ps_globals'
http_session_vars zval) to the session hashtable are wrecked when doing
this so this seems not to be a ext/session issue but more of a core
issue.

----
Dump in php_session_flush:
gdb> print (*ps_globals.http_session_vars).value
$5 = {lval = 0x5a5a5a5a, dval = 1.7838867517321418e+127, str = {val =
0x5a5a5a5a <Address 0x5a5a5a5a out of bounds>, len = 0x5a5a5a5a}, ht =
0x5a5a5a5a, obj = {handle = 0x5a5a5a5a, handlers = 0x5a5a5a5a}}

Reproduce code:
---------------
<?php
session_start();

var_dump($_SESSION);

$_SESSION['test'] = 'blubb';
$_SESSION['foo'] = 'test';

foreach($_SESSION as $key => $val) {
        unset($_SESSION['test']);
}

var_dump($_SESSION);
?>


Expected result:
----------------
On first run:
array(9) {
}
array(1) {
  ["foo"]=>
  string(4) "test"
}

On second run:
array(1) {
  ["foo"]=>
  string(4) "test"
}
array(1) {
  ["foo"]=>
  string(4) "test"
}

Actual result:
--------------
On every run:
array(9) {
}
array(1) {
  ["foo"]=>
  string(4) "test"
}

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

Reply via email to