From: bugs dot php dot net at enca dot cz Operating system: MS Windows Server 2003 PHP version: 5.0.4 PHP Bug Type: Session related Bug description: session unset inside foreach breaks session write handler
Description: ------------ In this testcase the "write" function is not called. If you remove line with "unset", the write function is called properly. If you delete whole foreach cycle and use "unset($_SESSION['A']);" instead, the "write" function si also called - as expected. This bug appear only when you call "unset" inside foreach cycle. My environment: MS Windows Server 2003 SE (Windows NT 5.2 build 3790) Apache/2.0.53 (Win32) PHP/5.0.4 Smilar (but not exactly same) bug is described as #32564, but it is in the No feedback status and there is no way (for me) to change this status. I hope that this "reproduce code" is much better then codes from #32564 I can provide more information if you ask for them. Reproduce code: --------------- <?php function foo(){return(true);} function read($id){ return 'A|s:1:"a";B|s:1:"b";'; } function write($id, $sess_data){ print "I'm writing this data: $sess_data\n"; return true; } header('Content-Type: text/plain'); session_set_save_handler("foo", "foo", "read", "write", "foo", "foo"); session_start(); print_r($_SESSION); foreach($_SESSION as $lsKey => $lsVal){ if($lsKey != 'A'){ unset($_SESSION[$lsKey]); //<<<<<<<< if you comment this line, the write function is called properly } } print_r($_SESSION); ?> Expected result: ---------------- Array ( [A] => a [B] => b ) Array ( [A] => a ) I'm writing this data: A|s:1:"a"; Actual result: -------------- Array ( [A] => a [B] => b ) Array ( [A] => a ) -- Edit bug report at http://bugs.php.net/?id=32910&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32910&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32910&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32910&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32910&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32910&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32910&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32910&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32910&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32910&r=support Expected behavior: http://bugs.php.net/fix.php?id=32910&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32910&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32910&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32910&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32910&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32910&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32910&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32910&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32910&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32910&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32910&r=mysqlcfg