Well I guess this is not a normal how-to-do-this-or-that stackoverflow question, but perhaps someone could enlighten me of a better approach for this question.
I've created an interface that could inherit different "engines" depending on a value and return the same object for all engines. This is a short time flat rentals application that has some integration with other applications in other states, obviously each one has a API, so I have to know how to send and receive each one differently and inside my application to be able to have the same object for all APIs. What I do exactly is I initialize something like this.
$flat = new API(array('engine' => 'some_api')); // the array has some more information inside but it is unimportant for the question
Now I have a list of IDs that each of them is for a different API. Something like
$list = array(1 => 'api_1', 2 => 'api_2'); // and more ...
Now for the question!
When iterating over the $list
what would you think is better,
Retaining all the possible engines inside the API object and for each ID I already have the "engine" initialized inside the API object (probably better speed/performance as everything is already allocated) or should foreach ID create a new API object with only the right "engine" initialized. (Lesser speed/performance but should be better on the memory management).
The API object has no meaning outside of the scope of the iteration so there is no need to retain it further down the line, but perhaps there would be less garbage collection overhead all in all if I just initiate one object instead of say 2 or 4 for the amount of IDs I have.
Any thoughts?