View Single Post
Old 08-25-2009, 07:06 PM   #8 (permalink)
Fordi
The Visitor
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Fordi is on a distinguished road
Default

Quote:
Originally Posted by Prpl_Ppl_Etr View Post
I'm having some trouble getting my Singleton to hold state.

I have a class that implements the Singleton pattern and has a member called $sessionState which is meant to hold a string value denoting the current state of the Singleton instance.
Oooo... session-level singleton. Not a bad idea, especially in the case of, for example, a User or Visitor model.

Still, your best bet with that is to store the class instance in the $_SESSION variable, and define the __sleep and __wakeup methods accordingly.

Quote:
What am I missing? Are Singleton instances cleared/collected with subsequent http requests to the same php file?
Yes. Yes they are. In fact, between requests, the only things that hang out are the contents of $_SESSION (if session_start() has been called), files, and databases. No other variables are retained.
Fordi is offline  
Reply With Quote