在第二次从数据库调用时,Doctrine Collection的对象被DB值替换

Need to change some object values of a doctrine collection fetched from database and save again to the database. For this, there is a old written code and In that they have used a loop to save objects one by one. The reason of saving objects one by one is because there some other processes are done in the middle. In the end of the first loop there is a function which is trying to fetch another doctrine collection from the database. Now that entire collection is existed of db values. Because of that 1st collection is replaced by existing database values. So updating process is not working. Why is this happening ?

Example Code :

class mainAction extends sfAction {

      function execute($request) {
          $a = new ExampleA();
          $collection = $a->updateDoctrineCollectionWithNewValues(6);

          $b = new ExampleB();
          $b->saveDoctrineCollectionToDB($collection);
      }
}

class ExampleA {

    function updateDoctrineCollectionWithNewValues($empNumber){
       $empSalaryComponents = Doctrine_Core::getTable('EmployeeSalaryComponent');

    $empSalComCollection = $empSalaryComponents->findBy('employee_number', $empNumber);

    foreach ($empSalComCollection as $empSalComponent) {
        $empSalComponent->setValue(9999999999999);
    }

    return $empSalComCollection;
}

}

 class ExampleB {

       function saveDoctrineCollectionToDB($doctrineCollection){
            var_dump($doctrineCollection->toArray()); // 1st var_dump
            foreach ($doctrineCollection as $object) {
              $this->addToLogger($object);
              var_dump($doctrineCollection->toArray()); //2nd var_dump
              die;
            }
       }

       function addToLogger($object) {
          $empSalaryComponents = Doctrine_Core::getTable('EmployeeSalaryComponent')->findBy('employee_number', $object->getEmployeeNumber());
           /**
             * Do something
           **/
       }

}

Results

1st var_dump :

array (size=4)
  0 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '1' (length=1)
      'value' => int 9999999999999
      'effectiveDate' => string '2019-01-15' (length=10)
      'is_active' => string '1' (length=1)
  1 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '2' (length=1)
      'value' => int 9999999999999
      'effectiveDate' => string '2019-01-15' (length=10)
      'is_active' => string '1' (length=1)
  2 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '3' (length=1)
      'value' => int 9999999999999
      'effectiveDate' => string '2019-01-15' (length=10)
      'is_active' => string '1' (length=1)
  3 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '4' (length=1)
      'value' => int 9999999999999
      'effectiveDate' => string '2019-01-19' (length=10)
      'is_active' => string '1' (length=1)

2nd var_dump:

  0 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '1' (length=1)
      'value' => string '6787' (length=4)
      'effectiveDate' => string '2019-01-15' (length=10)
      'is_active' => string '1' (length=1)
  1 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '2' (length=1)
      'value' => string '71111' (length=5)
      'effectiveDate' => string '2019-01-15' (length=10)
      'is_active' => string '1' (length=1)
  2 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '3' (length=1)
      'value' => string '34%' (length=3)
      'effectiveDate' => string '2019-01-15' (length=10)
      'is_active' => string '1' (length=1)
  3 => 
    array (size=5)
      'employee_number' => string '6' (length=1)
      'salary_component_id' => string '4' (length=1)
      'value' => string '6787' (length=4)
      'effectiveDate' => string '2019-01-19' (length=10)
      'is_active' => string '1' (length=1)

2nd var_dump is filled with db values since calling db in the middle of the loop.

Env : Doctrine 1.2, Php7.2, Symfony 1.4