hello I am using zend framework and i am trying to combine it with doctrine. Not the hardest thing to do but what I wanted to do is a class with a static member that will be the entity manager and I want to create it just ONCE in THE WHOLE APPLICATION CONTEXT.
When I was playing with static variables in php to learn how it works in order to do what I want I realize that php creates a new instance of a static variable in each request. So the static variable only remains static through the request not the entire application is that correct, can someone tell how to do static variables for the whole application no matter the request that came to the server.
You can’t do this with PHP directly, you’d need some kind of persistence, like serializing the object and saving it in a database, and even then, you’re going to run into a lot of concurrency issues.
PHP not only creates a new instance of each static variable for each request, it basically runs your entire application with each request. In fact, assuming you’re running a web server like apache, it’s running more than one instance of your application at once, since apache is capable of handling mutiliple requests at once. So even if you were able to serialize an object to a some sort of persistence like a database, you’d probably be overwriting changes that another instance of your application had made to it.