title: Pass reference to $this in constructor PHP
body: <p>I've got a class called <code>Request</code>. At some point in that class I create a new controller using the following code, passing <code>$this</code> in the constructor:</p>
  
  <pre><code>$controller = new $this-&gt;_controllerName($this);
  </code></pre>
  
  <p>My controller constructor is as follows:</p>
  
  <pre><code>public function __construct(Request $request) {
      parent::__construct($request);
  
      // More stuff
  }
  </code></pre>
  
  <p>If I modify <code>$request</code> in either this object or its parent object, the values don't change in the object that originally called it. I also tried changing the constructor definition to <code>public function __construct(Request &amp;$request) {</code> (as said on <a href="http://php.net/manual/en/language.references.pass.php" rel="nofollow" title="php.net">php.net</a>), but that doesn't work either. How can I fix this?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Edit 1:</strong> As asked some code that shows what I do with <code>$request</code>. The class has a public property called <code>_response</code> which has a public property called <code>_body</code>. In one of my methods I do the following:</p>
  
  <pre><code>$this-&gt;_request-&gt;_response-&gt;_body = $this-&gt;_template-&gt;_render();
  </code></pre>
  
  <p>Now, I need the request from which I called the method to have the same <code>_request</code> property, so that I can get the body.</p>
  
  <p>I forgot to mention that I unset the object right after calling the method, is that a problem?</p>
  
  <p><strong>Edit 2:</strong> As pointed out below it does actually work, but it somehow doesn't work anymore when I call it from my <code>__destruct()</code> function. Why is that the case?</p>