0
It is possible to keep objects in memory during a session in PHP or you need to use the "Session" variable to store the previously instantiated objects?
The goal is to create a web system similar to a conventional OO application, only in case the server waits for the user’s response to modify the state of the objects. As far as I understand it, every new request will need to recreate the objects instead of changing the state of the ones that already existed. Is there any way to keep them in memory?
What you mean by session in this context?
– Woss
Thank you for your interest in answering the question, Anderson! Session, start and end set of a number of services. My idea is to implement the services through Objects that would be available while the session is logged in by the user, but from what I understood from the readings I did before I asked this question is that there is no way to keep objects in memory while waiting for user interaction.
– user3081078
Why would you want to do that?
– bfavaretto
Good afternoon, bfavaretto! Thanks for the comment. The goal is to create a web system similar to a conventional OO application, only in case the server waits for the user’s response to modify the state of the objects. As far as I understand, each new request will be necessary to recreate the objects instead of changing the state of the ones that already existed, which to me does not seem something practical or interesting... Precisely why the question.
– user3081078
@user3081078 which is one of the reasons I abhor the use of OOP in PHP. Very cool that you have had this concern, is around, I think you are starting to realize something that unfortunately many people who "think you understand" PHP did not stop to think. In most cases, while the OOP code is reassembling the object that came from the previous script, the procedural code has already done what it had to do and finished a long time ago. They took a concept that came from languages that maintain the state, and applied it to a script engine, which ironically... does not maintain state, which is basic to justify an object.
– Bacco
Thank you for the reply @Bacco! I am happy and sad at the same time to know that I will need to work with serialization, since the language of the system has already been established. I appreciate the contribution!
– user3081078
Or you can use PHP as it was originally designed, tending to the procedural and leaving OOP aside :D - Probably the code will get, among other things, more readable and absurdly thinner - remembering that as the language allows, you can use the two paradigms as convenience.
– Bacco
Not necessarily with serialization. You can reinstall everything with every request. Not necessarily serializing/deserialize will give you performance gains. Or you can follow @Bacco’s suggestion :)
– bfavaretto
These @Bacco comments should be an answer, and those canonical ones should stand out
– Maniero
You may not want to "radicalize" to the point of @Bacco’s suggestion to abandon OOP, but it’s no use wanting to make the application work in the same way as in environments that maintain status. In my opinion, serializing the state is the worst way out, unless it solves some performance issue that the application is facing.
– bfavaretto
Guys, thank you for your contributions. I think I’m going to have to create a mechanism for serializing the state of the objects in which this is necessary. Unfortunately I need to use PHP and, at the moment, recreate all the mechanisms I had designed will take time that I do not have for the project! And I agree with Maniero, @Bacco’s comments certainly served as an answer to my question.
– user3081078
One last addendum, is there any backend web language other than Java Server Pages that maintains the state of the created objects? I got this flea behind my ear also with Python (Django) and Javascript (Node.js).
– user3081078