title: Add object to php array in symfony
body: <p>I currently have 2 classes:</p>
  
  <ol>
  <li>workerListClass</li>
  <li>workerClass</li>
  </ol>
  
  <p>The workerListClass gets a list of work with ids from database. For each of these the workerClass is called</p>
  
  <pre><code>foreach ($query as $value) {
          $result = $this-&gt;worker-&gt;getWorkerById($value['ID']); // DB Call to get additional data
          $this-&gt;addData($result);
  
          vardumper::dump($result-&gt;getId());
          // This results in 1031 and 1528
      }
  </code></pre>
  
  <p>addDate is very simple</p>
  
  <pre><code>public function addData(workerClass $worker): void
  {
      $this-&gt;data[] = $worker;
  }
  </code></pre>
  
  <p>But if i try to go through this array something strange happens</p>
  
  <pre><code>        $result = $this-&gt;workerListClass-&gt;getWorker()-&gt;getData();
      foreach ($result as $worker) {
          vardumper::dump([
              $worker-&gt;getId() // this outputs 1528 twice!!!
          ]);
      }
  </code></pre>
  
  <p>getData does nothing special</p>
  
  <pre><code>public function getData(): array
  {
      return $this-&gt;data;
  }
  </code></pre>
  
  <p>Can someone help me why this outputs 1528 twice?</p>