Page 1 of 1

Static variables in PHP without using SESSION

Posted: Wed Mar 30, 2005 7:42 am
by fingertips
Please help

I am new at PHP and come from an ASP environment. I want to know if there is anyway in using static variable and not having a new environment each time a script is called. I am using classes to store information during a users visit to the web site, but everytime I call the script (same file) I need to re-initiliaze my class variables.

I am using SESSION variable for a workaround thereby populating the SESSION variables from the class variables at the end of the script and then populating the class variables from the SESSION variables at the beginning of the script. I find this very sloppy.

Is there any neater way to do this.

In ASP you couls initialize variables withing the *.asa file. Isn't there anything simmalar for PHP.

Gerhard

Posted: Wed Mar 30, 2005 10:08 am
by Maugrim_The_Reaper
Passing the object through SESSION may be an option - not entirely sure of the consequences of such a move... serialise() is a reference to look for in the manual.

Posted: Wed Mar 30, 2005 10:32 am
by feyd
unless you use shared memory (which will then be available to ALL users), sessions are the way to go. serialize() isn't needed, as the session system serializes the data before storage anyways.