title: What are the advantages of using getters and setters instead of functions or simply public fields in PHP?
body: <p>I'm not a PHP developer, so I'm wondering what the advantages and disadvantages are in PHP to using explicit getter/setters, in a pure OOP style, with private fields (the way I like):</p>
  <pre><code>class MyClass {
      private $firstField;
      private $secondField;
  
      public function getFirstField() {
          return $this-&gt;firstField;
      }
      public function setFirstField($x) {
          $this-&gt;firstField = $x;
      }
      public function getSecondField() {
          return $this-&gt;secondField;
      }
      public function setSecondField($x) {
          $this-&gt;secondField = $x;
      }
  }
  </code></pre>
  <p>or just public fields:</p>
  <pre><code>class MyClass {
      public $firstField;
      public $secondField;
  }
  </code></pre>