title: PHP Infinite recursion when serializing object with Dependency Injection
body: <pre><code>class foo
  {
   private $deps
  
   public function __construct(bar $obj)
   {
    $this-&gt;deps=$obj;
   }
  }
  
  
  class Bar
  {
    private $property; //Instance of Bar which have setter and getter methods
  
  }
  </code></pre>
  
  <p>Both implements an interface which serialize the objects to XML. But it is get into infinite recurrsion Due to cross refference. How to resolve this? Is this my design fault? How to improve it?</p>
  
  <p>One way i can think of last time cleanup of dependency before serializing. But i dont know it will be best way or not.</p>