rwilkerson Posted September 26, 2007 Share Posted September 26, 2007 I'm working on my first PHP application in...years, and I just created a few singletons. I didn't think too much about it since I understand static members and the like, but in the course of doing some reading I bumped into a very basic question... Since the internet is a stateless environment, what mechanism does PHP use to "persist" the object instantiation across requests? In other words, how does PHP know that a class has already been instantiated 3 or 4 requests after the instantiation occurred? The question seems fairly academic at the moment (my singletons seem to be working as expected), but a deeper understanding can never be bad...can it? Any insight would be appreciated. Rob Wilkerson Quote Link to comment https://forums.phpfreaks.com/topic/70742-academic-question-re-singletons/ Share on other sites More sharing options...
leonglass Posted September 26, 2007 Share Posted September 26, 2007 I think, serialisation aside, that your objects don't persist across requests. Your singleton is created as such per run of the interpreter i.e. each request. Quote Link to comment https://forums.phpfreaks.com/topic/70742-academic-question-re-singletons/#findComment-355843 Share on other sites More sharing options...
Daniel0 Posted September 26, 2007 Share Posted September 26, 2007 In other words, how does PHP know that a class has already been instantiated 3 or 4 requests after the instantiation occurred? It doesn't. It creates a new instance per each request as the script is parsed on each request. Quote Link to comment https://forums.phpfreaks.com/topic/70742-academic-question-re-singletons/#findComment-355858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.