#23572 [Opn]: unable to access session vars after adding $GLOBALS

From: Date: Sat, 10 May 2003 03:27:00 +0000
Subject: #23572 [Opn]: unable to access session vars after adding $GLOBALS
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39412@lists.php.net to get a copy of this message
ID: 23572 User updated by: nospam at mckenzies dot net Reported By: nospam at mckenzies dot net Status: Open Bug Type: Unknown/Other Function Operating System: Windows XP Pro PHP Version: 4.3.1 New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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 (#39412) next »