title: How to convert a PHP Object with private properties that are Objects into an array using Zend Hydrator?
body: <p><strong>Code</strong></p>
  
  <pre><code>class Composite
  {
  
      private $a;
  
      private $b;
  
      /**
       *
       * @return the $a
       */
      public function getA()
      {
          return $this-&gt;a;
      }
  
      /**
       *
       * @return the $b
       */
      public function getB()
      {
          return $this-&gt;b;
      }
  
      /**
       *
       * @param field_type $a            
       */
      public function setA($a)
      {
          $this-&gt;a = $a;
      }
  
      /**
       *
       * @param field_type $b            
       */
      public function setB($b)
      {
          $this-&gt;b = $b;
      }
  }
  
  $composite = new Composite();
  $composite-&gt;setA(1);
  $composite-&gt;setB(new Composite());
  $composite-&gt;getB()-&gt;setA(2);
  $composite-&gt;getB()-&gt;setB(3);
  
  $x = new \Zend\Hydrator\ClassMethods();
  print_r($x-&gt;extract($composite));
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Array
  (
      [a] =&gt; 1
      [b] =&gt; Composite Object
          (
              [a:Composite:private] =&gt; 2
              [b:Composite:private] =&gt; 3
          )
  
  )
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>My goal is to produce an array out of an object where array can be recursive.  Zend provides a hydrator that extracts object properties and puts them into array.  But it does so on the first level only and it does not recurse further (i.e. it left private members as-is above, when I wanted them to be turned into an array).</p>
  
  <p>Is there any way to produce an array out of an object like this?  Note:  I have different objects as private members, they are not the same object as is in this simplified example.</p>
  
  <p>Hydrator in question does not go on to extract private object properties recursively.</p>
  
  <p>I will accept other answers that do not use Hydrator, provided they are reasonably elegant, but if an answer that uses <code>\Zend\Hydrator</code> emerges, I will accept that one.</p>