title: Parameter vs. Member variables
body: <p>I've recently been working with someone else's code and I realized that this individual has a very different philosophy regarding private variables and method parameters than I do. I generally feel that private variables should only be used in a case when:</p>
  
  <ol>
  <li>The variable needs to be stored for recall later.</li>
  <li>The data stored in the variable is used globally in the class.</li>
  <li>When the variable needs to be globally manipulated (something decidedly different from the need to read the variable by every class method).</li>
  <li>When it will make programming substantially easier. (Admittedly vague, but one has to be in many circumstances to avoid painting oneself into a corner).</li>
  </ol>
  
  <p>(I admit, that many of the above are slightly repetitive, but they each seem different enough to merit such treatment... )<br /><br />
  It just seems that this is the most efficient means of preventing changing a variable by accident.  It also seems like following these standards will allow for the eventual manipulation of external references (if the class is eventually modified), thus leaving you with further options in the future.  Is this simply a style issue (like one true bracket or Hungarian naming conventions), or do I have justification in this belief? Is there actually a best practice in this case?</p>
  
  <p><strong>edit</strong><br />
  I think this needs to be corrected. I used "globally" above where I actually meant, "globally by instance methods" not "globally accessible by anything, anywhere".<br /><br />
  <strong>edit2</strong><br />
  An example was asked for:</p>
  
  <pre><code>class foo
  {
      private $_my_private_variable;
  
      public function __constructor__()
      {
      }
  
      public function useFoo( $variable )
      {
          // This is the line I am wondering about,
          // there does not seem to be a need for storing it.
          $this-&gt;_my_private_variable = $variable; 
          $this-&gt;_doSometing();
      }
  
      private function _doSomething()
      {
  
          /*
            do something with $this-&gt;_my_private_variable.
          */
          // This is the only place _my_private_variable is used.
          echo $this-&gt;_my_private_variable;
      }
  }
  </code></pre>
  
  <p>This is the way I would have done it:</p>
  
  <pre><code>class foo
  {
  
      public function __constructor__()
      {
      }
  
      public function useFoo( $variable )
      {
          $this-&gt;_doSometing( $variable );
      }
  
      private function _doSomething( $passed_variable )
      {
          /*
            do something with the parameter.
          */
          echo $passed_variable;
      }
  }
  </code></pre>