Session bug reported
| From: | Shawn McKenzie | Date: | Sat, 10 May 2003 15:43:27 +0000 |
| Subject: | Session bug reported | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-147121@lists.php.net to get a copy of this message | ||
OK, i submitted it as a bug since no one had a clue. 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 various methods 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 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
}
//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
Thanks!
Shawn