So I have an MVC-style framework I’m working on, and I would like to give it the following functionality:
Any number of instances of a model with a certain ID can be created at once, but as soon as a save() method is called on one of these instances, all references to other models with the same ID will now point to the saved one.
The problem comes when I try to track all the references to the different instances of the same model. What I would like to do is store all of the instances in an array, then instead of returning references to the objects themselves when they are pulled, I would return references to the positions in the array. That way, when I save, I can simply go through the array and set each entry to a reference to the saved instance.
As far as I know, however, this is not possible with PHP. Is there any other alternative or perhaps a pattern that is used for cases like this?