title: Calling the variable property directly vs getter/setters - OOP Design
body: <p>I know this is probably subjective but I read this <a href="http://code.google.com/speed/articles/optimizing-php.html">optimization page from Google for PHP</a> and they suggest use the variable property directly without the need of getters and setters. Understandably I see the performance gain in this but is this really a good design practice to follow?</p>
  
  <p>Their Example using getter/setter:</p>
  
  <pre><code>class dog {
    public $name = '';
  
    public function setName($name) {
      $this-&gt;name = $name;
    }
  
    public function getName() {
      return $this-&gt;name;
    }
  }
  
  $rover = new dog();
  $rover-&gt;setName('rover');
  echo $rover-&gt;getName();
  </code></pre>
  
  <p>Suggested Optimization:</p>
  
  <pre><code>$rover = new dog();
  $rover-&gt;name = 'rover';
  echo $rover-&gt;name;
  </code></pre>
  
  <p>This would be a welcome change in my design process as I see the need for getters/setters going away, but what other hurdles/benefits might occur in doing this?</p>