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 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. 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. Link to comment https://forums.phpfreaks.com/topic/70742-academic-question-re-singletons/#findComment-355858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.