#23572 [Fbk->NoF]: unable to access session vars after adding $GLOBALS

From: Date: Sun, 18 May 2003 16:54:34 +0000
Subject: #23572 [Fbk->NoF]: unable to access session vars after adding $GLOBALS
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39888@lists.php.net to get a copy of this message
ID: 23572 Updated by: sniper@php.net Reported By: nospam at mckenzies dot net -Status: Feedback +Status: No Feedback Bug Type: Session related Operating System: Windows XP Pro PHP Version: 4.3.1 New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. Previous Comments: ------------------------------------------------------------------------ [2003-05-13 19:57:19] sniper@php.net Please try using this CVS snapshot: http://snaps.php.net/php4-STABLE-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-STABLE-latest.zip ------------------------------------------------------------------------ [2003-05-09 22:27:00] nospam at mckenzies dot net The //This doesn't work: //page2.php at the bottom, refers to using the //page1.php at the very top of the post. Thanks! Shawn ------------------------------------------------------------------------ [2003-05-09 22:20:28] nospam at mckenzies dot net PHP 4.3.1 as mod. dev box phpinfo() is here: http://pvt.mckenzies.net/phpinfo.php I am writing a session class and have various methods to set and get session vars. I have one method that extracts all session vars. I also have one that registers $GLOBALS in the session. I had never intended to do an extract of all the vars after registering the $GLOBALS, but during the course of testing it came up. Doesn't work. //page1.php session_start(); $test = "Test stuff"; foreach($GLOBALS as $var => $val) { $_SESSION[$var] = $val; } //This works: //page2.php session_start(); $var = "test"; $$var = $_SESSION[$var]; echo $test; //outputs: Test stuff //This also works: //page1.php session_start(); $test = "Test stuff"; $test2 = "more Test stuff"; $_SESSION['test'] = $test; $_SESSION['test2'] = $test2; //page2.php session_start(); foreach($_SESSION as $var => $val) { $$var = $val; echo $var; //outputs: test test2 } echo $test; //outputs: Test stuff echo $test2; //outputs: more Test stuff //This doesn't work: //page2.php session_start(); foreach($_SESSION as $var => $val) { $$var = $val; echo $var; //outputs: many keys but NEVER test } echo $test; //outputs: Notice: Undefined variable: test print_r($_SESSION); //outputs: many keys including [test] => 'Test stuff' if(array_key_exists("test", $_SESSION)) { echo "TEST FOUND"; //outputs: TEST FOUND } Thanks! Shawn ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23572&edit=1

« previous php.bugs (#39888) next »