Session variable scope - surprise!

From: Date: Mon, 04 Mar 2002 14:56:50 +0000
Subject: Session variable scope - surprise!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-87098@lists.php.net to get a copy of this message
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

« previous php.general (#87098) next »