title: PHP Getter and Setter Performance. Is performance important here?
body: <p>My Question is about performance vs design. I have readed much about Getter and Setter in PHP. And the idea behind, is very good and usefull (Debugging, Sanitize).</p>
  
  <p>So I started to do a Benchmark:</p>
  
  <pre><code>class Foo {
      public $bar;
  
      public function __construct($bar) {
          $this-&gt;bar = $bar;
      }
  
      public function getBar() {
          return $this-&gt;bar;
      }
  
      public function setBar($bar) {
          $this-&gt;bar = $bar;
      }
  }
  
  $foo = new Foo(42);
  Debug::ProcessingTimeSinceLastCall();
  
  //Without Setter and Getter
  for ($i = 0; $i &lt; 1000000; $i++) {
      if ($foo-&gt;bar === 42) {
          $foo-&gt;bar = 43;
      } else {
          $foo-&gt;bar = 42;
      }
  }
  Debug::ProcessingTimeSinceLastCall('No Setter and Getter');
  
  //With Getter and Setter
  for ($i = 0; $i &lt; 1000000; $i++) {
      if ($foo-&gt;getBar() === 42) {
          $foo-&gt;setBar(43);
      } else {
          $foo-&gt;setBar(42);
      }
  }
  Debug::ProcessingTimeSinceLastCall('With Setter and Getter');
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>0.0000 Seconds (First call)
  0.1428 Seconds (No Setter and Getter)
  0.4366 Seconds (With Setter and Getter)
  </code></pre>
  
  <p>Setter and Getter takes 3 times more time. Is my Benchmark wrong?</p>
  
  <p>I am in development of an big application, with thousands of those calls. Is it still a good practise to have getter and setter, if performance matters?</p>