Hi, I was wondering, can a static class take the place of a session?
For instance, if i have a static class that access a DB and stores the result in a static var, once that class has been instantiated how long will it be available?
Basically I want to only access the DB once and store the info so I don't have to query the DB every time I need the same info.
Thanks!
Static class question
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Static class question
PHP is a stateless paridigm. Like most things in PHP, they only live throughout the lifespan of the request. I.e., once the request is completed, the memory is dumped.
Sessions are a perfectly acceptable solution for this.
Sessions are a perfectly acceptable solution for this.
-
greetification
- Forum Newbie
- Posts: 4
- Joined: Thu Apr 22, 2010 3:19 pm
Re: Static class question
Thanks John,
I'm working on my first php oop project (trying to utilize my AS3 oop knowledge) so i'm still trying to get the hang of things.
So if it is stateless, what is the point of setting anything as static, is it only if you don't want to use a constructor?
Thanks!
I'm working on my first php oop project (trying to utilize my AS3 oop knowledge) so i'm still trying to get the hang of things.
So if it is stateless, what is the point of setting anything as static, is it only if you don't want to use a constructor?
Thanks!