note 69443 added to function.unset

From: Date: Wed, 06 Sep 2006 12:47:31 +0000
Subject: note 69443 added to function.unset
Groups: php.notes 
Request: Send a blank email to php-notes+get-116755@lists.php.net to get a copy of this message
_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 ---- Server IP: 193.198.184.18 Probable Submitter: 83.131.105.158 ---- Manual Page -- http://www.php.net/manual/en/function.unset.php Edit -- https://master.php.net/note/edit/69443 Del: integrated -- https://master.php.net/note/delete/69443/integrated Del: useless -- https://master.php.net/note/delete/69443/useless Del: bad code -- https://master.php.net/note/delete/69443/bad+code Del: spam -- https://master.php.net/note/delete/69443/spam Del: non-english -- https://master.php.net/note/delete/69443/non-english Del: in docs -- https://master.php.net/note/delete/69443/in+docs Del: other reasons-- https://master.php.net/note/delete/69443 Reject -- https://master.php.net/note/reject/69443 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116755) next »