Forum Moderators: coopster

Message Too Old, No Replies

Static scope

         

matthewwithanm

5:37 am on Aug 6, 2006 (gmt 0)

10+ Year Member



This should be a really simple question, but I can't seem to find the answer..

In server-side scripting, to whom are static members available? Since it's executing on the server, can one visitor get a static property value that was set by the actions of another?

Thanks!

FalseDawn

2:46 pm on Aug 6, 2006 (gmt 0)

10+ Year Member



Variables with static scope are generally used in classes/functions to retain their values between function/method calls in a single script execution.

Web developing is _stateless_, and it appears you don't fully grasp what this means.

The only way that data can be passed between users (or indeed from page to page for the _same_ user) is to maintain state in some way (usually done by sessions and a cookie for each user), or of course by using permanent storage such as files or a database.

Data _can_ be passed between different users, but this is generally either due to a programming error (like posting a link somewhere with a session ID in the URL, or possibly a faulty implementation of a shared memory cache) or deliberate by design, but never by static variables.

[edited by: FalseDawn at 2:47 pm (utc) on Aug. 6, 2006]

matthewwithanm

3:49 pm on Aug 6, 2006 (gmt 0)

10+ Year Member



Thanks, FD.

I've always understood HTTP to be stateless but I don't know how one can say "Web Developing" is stateless. If, through my actions, a process begins to run on the server, it's feasible that the process could still be running when another user attempts to run it. Otherwise, we wouldn't need to do things like lock tables.

So, really, I don't think my question is so much about the stateless nature of HTTP, but rather how a server treats the static keyword. Specifically, if somebody attempts to execute a script while it is being run by another user, can I be sure they will not have access to static members created by that user, and why?

Thanks again for the quick response!

smells so good

4:18 pm on Aug 6, 2006 (gmt 0)

10+ Year Member



Each user that executes the script will be doing so within a unique session, and nothing from one session will be (or should be) available to another session. This would include any value of the variables within the script. So the scope of your script and its variables is limited within the session.

can one visitor get a static property value that was set by the actions of another?

No. Not without some sort of referal.

matthewwithanm

4:21 pm on Aug 6, 2006 (gmt 0)

10+ Year Member



Thanks, smells! That's exactly the info I was looking for.