title: how to call a variable in a public function from another function within the same class in php
body: <pre><code>&lt;?php  
  class Pen  
  {  
      public $color;  
      public function clr()  
      {  
          $this-&gt;color = "Red";  
      }  
      public function write()  
      {  
          echo $this-&gt;color; //if i write $ before color it gives me an error
      }  
  }  
  $a = new Pen();  
  $a-&gt;write();  
  ?&gt;
  </code></pre>
  
  <p>i tried to write an $ dollar in the write() function but it gives me an error
  and in this code it shows nothing i even tried to use 
  "class name :: function name ()-> color ;" didn't work either
  i tried a lot of things that i found here but none of them really worked for me</p>