#23572 [Opn->Fbk]: unable to access session vars after adding $GLOBALS
| From: | sniper@php.net | Date: | Wed, 14 May 2003 00:57:20 +0000 |
| Subject: | #23572 [Opn->Fbk]: unable to access session vars after adding $GLOBALS | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-39583@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: Open
+Status: Feedback
Bug Type: Session related
Operating System: Windows XP Pro
PHP Version: 4.3.1
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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