title: Where do Zend\Db\ResultSet\ResultSet objects store the retrieved data?
body: <p>In a Zend Framework application, that is built pretty similar to the album application from the <a href="http://framework.zend.com/manual/2.1/en/user-guide/overview.html" rel="nofollow">ZF2 Getting Started tutorial</a>, I use a ResultSet object to transport the data from the model over the controller to the view (for details see the code below).</p>
  
  <p>This works fine, but I don't get, where the <code>ResultSet</code> object holds the data. I can loop it e.g. with <code>foreach</code> and get the data row byrow (or better model object by model object). But when I debug it in my IDE or simply with <code>var_dump(...)</code>, it seems to be empty.</p>
  
  <p>How/where does a <code>Zend\Db\ResultSet\ResultSet</code> object hold the data, retrieved from the database?</p>
  
  <p>The relevant parts of the code:</p>
  
  <p>Module settings:</p>
  
  <pre><code>class Module implements ConfigProviderInterface, ServiceProviderInterface, AutoloaderProviderInterface {
  ...
      public function getServiceConfig() {
          try {
              return array (
                  'factories' =&gt;array(
                      ...
                      'SportTable' =&gt; function ($serviceManager) {
                          $tableGateway = $serviceManager-&gt;get('SportTableGateway');
                          $table = new SportTable($tableGateway);
                          return $table;
                      },
                      'SportTableGateway' =&gt; function ($serviceManager) {
                          $dbAdapter = $serviceManager-&gt;get('Zend\Db\Adapter\Adapter');
                          $resultSetPrototype = new ResultSet();
                          $resultSetPrototype-&gt;setArrayObjectPrototype(new Sport());
                          return new TableGateway('sports', $dbAdapter, null, $resultSetPrototype);
                      },
                      ...
                  )
              );
          }
          ...
  }
  </code></pre>
  
  <p>Model (table):</p>
  
  <pre><code>class CourseTable {
          ...
      public function findAllByCityNameAndSportTitle($cityName, $sportTitle) {
          $select = new Select();
          $where = new Where();
          ...
          $resultSet = $this-&gt;tableGateway-&gt;selectWith($select);
          return $resultSet;
      }
      ...
  }
  </code></pre>
  
  <p>Model (mapper):</p>
  
  <pre><code>class Course implements ArraySerializableInterface {
  
      public $id;
      ...
  
      public function exchangeArray(array $data) {
          $this-&gt;id               = (isset($data['id'])) ? $data['id'] : null;
          ...
      }
      ...
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>class CatalogController extends AbstractActionController {
      ...
      public function listCoursesAction() {
          $cityName = $this-&gt;params()-&gt;fromRoute('city', null);
          $sportTitle = $this-&gt;params()-&gt;fromRoute('sport', null);
          return new ViewModel(array(
              'city' =&gt; $cityName,
              'sport' =&gt; $sportTitle,
              'courses' =&gt; $this-&gt;getCourseTable()-&gt;findAllByCityNameAndSportTitle($cityName, $sportTitle)
          ));
      }
      ...
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;?php foreach ($courses as $course) : ?&gt;
  &lt;div&gt;
      &lt;div&gt;id: &lt;?php echo $this-&gt;escapeHtml($course-&gt;id); ?&gt;&lt;/div&gt;
      ...
  &lt;/div&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>