Object Life Time in PHP - How many Controller instances?

Asked

Viewed 182 times

1

I have a controller that runs the index method for the main page. A button in profile information is called by a route that falls into the registration method. The instance that was executed when you ran the index still exists when I am running another call via get? Or does it go to each new request?

2 answers

1

It all depends on how you are programming, because nothing prevents you from being in one controller and sending a message to another, although this is not good practice.

Framewoks working with MVC usually have the following life cycle: MVC Life Cycle

That is, by default the controller does not store its status from one request to the other.

0

HTTP is a stateless protocol.
Briefly it means that each request is an independent transaction.

The whole process in PHP is compiled at runtime and "dies" when the build is complete.

In a second request, a new completely independent process of processes executed in previous or later requests is initiated.

However, there are several techniques to keep an instance "alive" in separate requests.

Obviously this is not only in PHP. It is the nature of the HTTP protocol.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.