title: How can I pass variables to a file included in a class in PHP?
body: <p>So I'm working on my own little MVC framework as a learning exercise. It's working great, but I want to be able to reference variables in my view files without $this.</p>
  
  <p>So for example I have a controller object which instantiates a view object. From the controller I pass the variables to the view like this</p>
  
  <pre><code>$this-&gt;view-&gt;foo = "bar";
  </code></pre>
  
  <p>Then the view object includes the relevant code for the view (eg: myView.phtml). So to access "foo" in the view file I use this</p>
  
  <pre><code>echo $this-&gt;foo;
  </code></pre>
  
  <p>But what I would like to do, and I don't know if this is possible or wether I'm missing something obvious, but what I would like to do is reference the variables like this</p>
  
  <pre><code>echo $foo;
  </code></pre>
  
  <p>Without me posting the entire source, can anyone point me in the right direction? </p>