I think session_register registers the variable and its value as a global.
In this case, $test's global value is nothing. nada. Because it doesn't exist globally. In the reg() function, what is being output is a LOCAL variable called $test. Not a global value. If you put the line global $test; into the reg() function so that it reads: function reg() { global $test; $test = 13; session_register("test"); echo "in reg(), test=<$test><br>"; } Then it should work as expected. Sure it *does* say in the docs somewhere that register_globals() is only applicable to global variables. 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 14:57 To: [EMAIL PROTECTED] Subject: [PHP] Session variable scope - surprise! This is a behavior I have not found documented, in fact the books I have read indicated that this would not be the case... given the script (with session.save_handler = files): <?php function reg() { $test = 13; session_register("test"); echo "in reg(), test=<$test><br>"; } session_start(); reg(); echo "test=<$test><br>"; ?> The output is: in reg(), test=<13> test=<> I was quite surprised, but at least now I know why my code isn't working. I assume that $test is going out of scope after the function reg() exits. BUT, isn't registering a variable as a session variable supposed to give it "superglobal" status? I thought so. Can someone give me the 'official' explanation of this behavior? Many thanks, Richard -- 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