php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23572 unable to access session vars after adding $GLOBALS
Submitted: 2003-05-09 22:20 UTC Modified: 2003-05-18 11:54 UTC
From: nospam at mckenzies dot net Assigned:
Status: No Feedback Package: Session related
PHP Version: 4.3.1 OS: Windows XP Pro
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nospam at mckenzies dot net
New email:
PHP Version: OS:

 

 [2003-05-09 22:20 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-09 22:27 UTC] 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-18 11:54 UTC] sniper@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 17:01:30 2024 UTC