#23572 [NEW]: unable to access session vars after adding $GLOBALS
| From: | nospam at mckenzies dot net | Date: | Sat, 10 May 2003 03:20:28 +0000 |
| Subject: | #23572 [NEW]: unable to access session vars after adding $GLOBALS | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-39411@lists.php.net to get a copy of this message | ||
From: nospam at mckenzies dot net
Operating system: Windows XP Pro
PHP version: 4.3.1
PHP Bug Type: Unknown/Other Function
Bug description: unable to access session vars after adding $GLOBALS
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 bug report at http://bugs.php.net/?id=23572&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=23572&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=23572&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=23572&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=23572&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=23572&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=23572&r=support
Expected behavior: http://bugs.php.net/fix.php?id=23572&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=23572&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=23572&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=23572&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23572&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=23572&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=23572&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=23572&r=gnused