Static variables in PHP without using SESSION

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fingertips
Forum Newbie
Posts: 1
Joined: Wed Mar 30, 2005 7:27 am
Location: South Africa

Static variables in PHP without using SESSION

Post 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
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply