title: Setting a variable in a class function, where can I use that variable
body: <p>If I have a class (like below) and in a function I set a variable (below:$this->example) but I havent declared the variable at the top of the class (e.g var $example;) where and how can I use this variable?  I tried using it straight away in another function but it didn't work (I guess I could have made a mistake but it worked after I declared it in the top of the class)</p>
  
  <p>I have seen this in Symfony for setting variables that you can use in the view and also I came accross it in Phorms to name a couple of examples.  </p>
  
  <p>Sorry if this is obvious, I would just like to understand how I can use these variables, including getting the name of the variable(e.g $this->example, by name I mean "example").</p>
  
  <pre><code>class ExampleClass{
    var $another_var;
    function __construct($data){
      $this-&gt;example = $data;
      $this-&gt;another_var = $data;
    }
  
    function exampleFunction(){
      $test = $this-&gt;example; //this doesnt work
      $another_test = $this-&gt;another_var; //this obviously does
    }
  }
  </code></pre>
  
  <p>Any help would be much appreciated</p>
  
  <p>Regards</p>
  
  <p>Luke</p>
  
  <p>EDIT: <em>(from my reply to DrColossus)</em></p>
  
  <p>I want to be able to set any variable name in a function and in another function grab any variables set with there name.For example in Symfony I can set $this->completly_random_name = $x in an action class function, then in the view I can use $completly_random_name. There is no way that symfony has set every possible combination of variable names in the top of the parent class.</p>