title: Strange use of class's variable (micro optimization ?)
body: <p>I'm fairly new in PHP, and I encounter what I see as a strange use of class variable (I use PHP 5.6 and I think to use 7.0, if that help).</p>
  
  <pre><code>Class Foo {
  
      private $bar = 'some string not returned nor modified and used in one place';
  
      public function Test($foobar)
      {
          if ($foobar === $this-&gt;bar) {
              // Some code
          } else {
              // Some code
          }
      }
  }
  </code></pre>
  
  <p>When I see above code, I asked my co-worker why $bar is declared as a class variable, and why not declare $bar only in method 'Test'.
  He answered by explaining me that declaring $bar in Test would result on a performance loss since each time method 'Test' will be call, it will result in re-create memory space for $bar variable.</p>
  
  <p>I'm little puzzled, is this true ? I understand the logic : if you declare your variable as a class variable, memory will be "allocated" once and not at each call, but I'm surprised that there is no automatic optimization to do this behind the curtain by php.</p>
  
  <p>Is this an old optimization ? It's a good thing to declare as much as possible variable as class variable ?</p>
  
  <p>Sorry for such a question, but I searched a little and I found nothing (mostly because I don't know which keyword I must type to get information on this particular subject).</p>