RE: [PHP] Session variable scope - surprise!

From: Date: Mon, 04 Mar 2002 16:02:58 +0000
Subject: RE: [PHP] Session variable scope - surprise!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-87113@lists.php.net to get a copy of this message
Then, when session_register("xxxx"); is called (even on a variable which is going out of scope) what actually happens? Where is the data actually stored? I know it isn't in the file yet (I have session.save_handler = files) because nothing is written to the file until the script exits. So the memory for xxxx should either be in free store or on the stack. And, the second question: how can this memory, and the data it contains, be accessed later in the script (after the session_register) without having to depend on the original variable being global or not? Indeed, it appears that unless the registered variable is global, session_register will not work. (Reference my test script appended below, which can be loaded multiple times with no effect) This is undocumented! Note: I am not complaining about documentation, I am just trying to understand what exactly is happening when you register a session variable. Richard <?php function reg() { $test = 13; session_register("test"); echo "in reg(), test=<$test><br>"; } session_start(); if (!session_is_registered("test")) reg(); echo "HTTP_SESSION_VARS[test] = <".$HTTP_SESSION_VARS["test"]."><br>"; ?>

« previous php.general (#87113) next »