|
Posted by Nils Bandener on 10/15/05 00:54
joes wrote:
> I noticed in my static example which I did in PHP that the static
> variable is not stored over multiple php pages. So this does differ
> than to other OO languages like JSP.
Ahem ... JSP is not directly an object oriented language. Java, on
which JSP is founded, is object oriented, though.
> Is this so or did I something
> wrong?
It is indeed the case that static variables behave differently in PHP
compared to Java. In the case of Java Servlets and/or JSP all the HTTP
requests are (generally) served by one Java Virtual Machine. Thus,
static variables of classes just exist once on a server and do not have
any notion of HTTP requests.
In PHP though, the PHP environment is newly created for each HTTP
request. Without further measures, the PHP scripts are even recompiled
for each request. So, static class variables are deleted after a
request has been completed.
You should note that in Java static variables are not only common to
the requests of a single session, but to all requests that arrive on
the server. Thus, you should think twice (better even more) before
using static variables in a JSP or Servlet environment. The most common
use case for static variables in these contexts is resource sharing
between the requests. One example for that is the Struts configuration.
Bye
Nils
Navigation:
[Reply to this message]
|