title: Merging two objects into one array
body: <p>I'm trying to put two objects into one array to loop through.</p>
  
  <pre><code>    $arr = array();
      while ($data = $d-&gt;fetch()) {
          $a = new aEntity();
          $b = new bEntity();
          $a-&gt;setData1($data['data1']);
          $b-&gt;setData2($data['data2']);
          $arr[] = (object) array_merge((array) $a, (array) $b);
      }
      return $arr;
  </code></pre>
  
  <p>How do I put the values of <code>$a</code> and <code>$b</code> into <code>$arr[]</code>?</p>
  
  <p>Using <code>array_merge()</code> throws the following error:</p>
  
  <blockquote>
    <p>Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 28672 bytes)</p>
  </blockquote>
  
  <p>Thank you for your help</p>