View Complete Thread | FoxWeb Forum Home
Search:
Date:    Msg ID:   
From:    Thread:   
Subject:   
You should never use public variables to save user-specific information between hits.  Whenever you declare a variable as public, this variable remains in memory only for that particular channel, even after the request is processed.  This means that:
  • Public variables only persist in the channel they were declared in.  They will not be available if the next request for a particular user is served by a different channel.
  • Public variables are shared by all users on the same channel so they can not be used to maintain state information.
In addition, public variables are cleared from a specific channel if a run-time script error occurs.
 
The only situation where public memory variables can be used is if they contain information that is not specific to a particular user or application.  For example, you should define your objects as public if their startup code takes too long and you do not want to define them at the beginning of every request.  If you chose to define your objects as public you should make no assumptions about the state of these objects (or even about whether they exist).  Before using the objects your code should first check for their existence (IF TYPE('ObjectName') = 'O') and then, either create them if they don't exist, or re-initialize all properties.

FoxWeb Support Team
support@foxweb.com email

Sent by Alan Harris-Reid on 01/25/2003 07:29:09 AM:
I have a Foxweb application in which I require some variables to be in scope for the entire lifetime of a session.  The question is, do I use public or session variables?  I intend initialising them in fw_enter if they don't already exist when calling a script.
 
What are the pros-and-cons of each method?  As far as I can see public variables are easier to program (myPubVar = myValue instead of Session.Setvar('mySessionVar',myValue)), but there must be other differences I have overlooked.
 
What about scoping?  When the session ends, are global variables destroyed as well as session varibles?
 
Any help would be appreciated.
Alan