>From the manual page for session_register on PHP.net:

"For each name, session_register() registers the global variable with that
name in the current session. "

I tried your script below. The following was created in my session file:

!test|

Which I'm guessing means a variable which has not been instantiated. If it
had held a value, it would look something like

test|i:13;

So to answer your questions...
Session_register on an undefined global variable produces something like the
above in the session file.
Accessing the value later in the script has to depend on it being global,
since to be registered in the session it has to be a global variable in the
first place.

HTH,

Richy

==========================================
Richard Black
Systems Programmer, DataVisibility Ltd - http://www.datavisibility.com
Tel: 0141 435 3504
Email: [EMAIL PROTECTED]


-----Original Message-----
From: Richard Fox [mailto:[EMAIL PROTECTED]]
Sent: 04 March 2002 16:03
To: PHP
Subject: RE: [PHP] Session variable scope - surprise!


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>";
?>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to