I have a static function in an object that does some stuff and returns an object like so:
$objectA = ObjectA::getItem();
Then I have a function that makes other types of objects and returns an array of them, part of these types of objects require the $objectA, so it gets passed in like so:
$arrayOfObjectB = ObjectB::getStuff($objectA);
When constructing the $arrayOfObjectB I change a part of $objectA which will be a part of $objectB.
Something like this:
public static function getStuff($objectA)
{
$arrayOfObjectB = array();
foreach(...loops through some stuff)
{
$objectA->setSomething($variableChangedDuringLoop);
$objectB = new ObjectB($objectA);
$arrayOfObjectB[] = $objectB;
}
}
what happens is that all of the $objectA->something in $arrayOfObjectB will have set to the same thing as the last item in the loop, what I would like to happen is for the $something to hold separate values set during the loop.
I could clone the objects each time during the loop and then set them, that would work. But this approach seems 'wrong'.