Answer the question
In order to leave comments, you need to log in
How to redefine an object from within?
I don’t know if this is possible at all, but the following idea arose, and the problem arising from it, It is
necessary to create several objects, each object makes several queries to the database to create.
As a result of the application, identical objects are often created, in order not to pull the base every time to create them, I decided to write references to the created objects into the global array, then when I call the constructor, I look to see if the object was created earlier, and if so, I copy it properties to this object. The method works great, but there is a nuance in that only public properties can be passed in this way. Maybe there is a better option?
There was also an option to create an object through a static method that will check whether the object was previously created and return either it or a new one, but I would like to bypass only the constructor
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question