title: PHP OOP: Scope of Properties/Methods
body: <p>Please advise what's going on here?</p>
  
  <p>We have the following classes working together:</p>
  
  <ul>
  <li>An abstract base class 'form element'</li>
  <li>An abstract 'container' class that
  extends the form element class and
  groups form elements</li>
  <li>A 'field' class that extends the
  container</li>
  </ul>
  
  <p>In the 'field' class we call a method from the 'form element' class named 'setErrors($vars)' that sets a property named 'hasErrors'. $vars carries a boolean.</p>
  
  <p>There is another method named 'hasErrors()' in the 'form element' class that we try to call in the 'field' class to test the result of the boolean previously set however it returns false.</p>
  
  <p>The hasErrors property that is initially declared as false is not being overwritten?</p>
  
  <p><strong>Form Element Class(Base)</strong></p>
  
  <pre><code>private $hasErrors = false;
  
  public function setErrors($flag)
  {
  ...
  $this-&gt;hasErrors = $flag;
  ...
  }
  
  public function hasErrors()
  {
  return $this-&gt;hasErrors;
  }
  </code></pre>
  
  <p><strong>Field Class</strong></p>
  
  <pre><code>public function validate($value)
  {
  ...
  $this-&gt;setErrors($foundErrors);//$foundErrors only local to this method
  ...
  }
  
  public function getField()
  {
  ...
     if($this-&gt;hasErrors())
     {
     //do something...
     }
  ...
  }
  </code></pre>
  
  <p>Why is the property 'hasErrors' not being overwritten? Would this have something to with the scope of inheritance between the different classes?</p>
  
  <p>Not sure how this works but thanks in advance.</p>