note 69443 deleted from function.unset by bjori
| From: | bjori@php.net | Date: | Fri, 27 Oct 2006 10:28:40 +0000 |
| Subject: | note 69443 deleted from function.unset by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119179@lists.php.net to get a copy of this message | ||
Note Submitter: oxai NOSPAM post dot htnet dot hr
----
_SESSION problems - tested version PHP 4.1.2 (4.1.2-7.woody5)
example:
---
session_start();
echo '<html><body>version: '.phpversion().'<br>';
var_dump($_SESSION); echo '(1)<br>';
if( ! isset($_SESSION['keychain']) )
{
$key = 'myKeyString';
$_SESSION["$key"] = 'myKeyedData';
$_SESSION['keychain'] = $key;
var_dump($_SESSION); echo '(2)<br>';
}
else
{
$key = $_SESSION['keychain'];
unset($GLOBALS['_SESSION'][$key]);
unset($GLOBALS[$key]); // *** without this line you still have a 'myKeyString' =>
'myKeyedData'
// unset($GLOBALS["!".$key]); // this does not clear the garbage from the session file
var_dump($_SESSION); echo '(2)<br>';
}
echo '<br><a href="http://' .
$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] .'?'. SID .
'">RELOAD</a>';
echo '</body></html>';
---
the output is
- 1st time:
version: 4.1.2
array(0) { } (1)
array(2) { ["myKeyString"]=> string(11) "myKeyedData"
["keychain"]=> string(11) "myKeyString" } (2)
- 2nd time:
version: 4.1.2
array(2) { ["myKeyString"]=> &string(11) "myKeyedData"
["keychain"]=> &string(11) "myKeyString" } (1)
array(1) { ["keychain"]=> &string(11) "myKeyString" } (2)
- 3rd and on:
version: 4.1.2
array(1) { ["keychain"]=> &string(11) "myKeyString" } (1)
array(1) { ["keychain"]=> &string(11) "myKeyString" } (2)
this IS the expected behaviour but it does NOT happen if you omit the line indicated with ***.
if you comment out the ***-line the third and later outputs are the same as the second one meaning
you did NOT get rid of the myKeyString entry.
also, even after doing this stunt some garbage is left inside the session file (ie. a string
"!myKeyString;" ). the (commented-out) line following the ***-line does not help. I was
unable to find a solution to this problem.
OTH PHP 4.4.1 (w/ zend 1.3.0) always has the "correct" behaviour.
hope this saves an hour or two of your life :)
oxai