|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-07 15:04 UTC] christian dot cal at gmx dot de
Description:
------------
I am using PHP as an apache2 modul.
When trying to unset all vars that are stored in $_SESSION i use a foreach loop combined with unset. This method crashes the apache2.
I moved from PHP 4.4.2 to 5.1.2. The unmodified code works for 4.4.2 but crashes the server when using 5.1.2.
Reproduce code:
---------------
foreach ($_SESSION as $key => $value){
unset($_SESSION[$key]);
}
Expected result:
----------------
All vars should be removed from $_SESSION
So i tried this:
$helper=&$_SESSION;
foreach ($helper as $key => $value){
unset($helper[$key]);
}
This code does what I have expected from the code above.
Also this works:
$helper=array_keys($_SESSION);
foreach ($helper as $key){
unset($_SESSION[$key]);
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
I recently figured out that apache crashed when running into an infinitive loop it ran by using header("Location: "), because the vars in $_SESSION wasn't unset by unset(). I believe the error with not unsetting vars in foreach() has been posted.I am able to reproduce this bug with php 5.1.4 on IIS 6. I also tried one of the solutions provided by the first comment: $helper=array_keys($_SESSION); foreach ($helper as $key){ unset($_SESSION[$key]); } ..but after a print_r($_SESSION), I got this. Note the Access Violation: The session is now: Array ( [numRecords] => 2 [curRecord] => 1 [curTab_r0] => Header [curPartyType_r1] => d [numDebtors_r1] => 1 [numSecured_r1] => 1 [numProperty_r1] => 1 [curTab_r1] => Document [OriginalDocPgcnt_r1] => 1PHP has encountered an Access Violation at 01E1CCA6 [curTab_r2] => Document [OriginalDocPgcnt_r2] => 2 [chkbox_doc_nonstd_r1] => false [curPartyType_r2] => d [numDebtors_r2] => 1 [numSecured_r2] => 1 [numProperty_r2] => 1 )Ugh, looks like I was affected by this bug after all.. the array_merge was a problem, but so was the foreach over the $_SESSION. I got my script working by using the trick provided in the first comment: $helper=&$_SESSION; foreach ($helper as $key => $value){ unset($helper[$key]); }No crash for me, but I confirm the bug with php version 5.2.0 under windows : no unset the variables The proposed solution is OK : $helper=&$_SESSION; foreach ($helper as $key => $value){ unset($helper[$key]); } Thanks