__get and __set not behaving as expected
<pre><code>&lt;?php
class BaseClass {
  protected $data = array("foo" =&gt; 0, "bar" =&gt; 0, "baz" =&gt; 0);

  public function __set($name, $value) {
    if( array_key_exists($name, $this-&gt;data)){
      $func = "set_$name";
      return call_user_func_array(array($this,$func),array($value));
    }
  }


  public function __get($name) {
    if ( array_key_exists($name, $this-&gt;data)){
      $func = "get_$name";
      return call_user_func_array(array($this,$func),array());
    }
  }

  public function __call($method, $args) {
    if (method_exists($this,$method)) {
      return call_user_func_array(array($this,$method),$args);
    }

    if (substr($method, 0, 4) == 'set_'){
      $var_name = substr($method, 4);
      if (!(array_key_exists($var_name, $this-&gt;data))){ 
        return FALSE;
      }
      $this-&gt;data[$var_name] = $args[0];
      return TRUE;
    }

    if (substr($method, 0, 4) == 'get_'){
      $var_name = substr($method, 4);
      if (!(array_key_exists($var_name, $this-&gt;data))){ 
        return FALSE;
      }
      return $this-&gt;data[$var_name];
    }
  }
}

class SubClass extends BaseClass {
  protected $baz_changed = FALSE;

  public function set_baz($value) {
    if ($value != $this-&gt;baz){
      print "\n\nthis-&gt;data BEFORE SET:  ";
      print_r($this-&gt;data);
      print "\n\nthis-&gt;baz:  ";
      print_r($this-&gt;baz);
      print "\n\nPASSED baz:  ";
      print_r($value);
      $this-&gt;baz = $value;
      print "\n\nbaz AFTER SET:  ";
      print_r($this-&gt;baz); // appears it was set 
      print "\n\nDATA ARRAY:  ";
      print_r($this-&gt;data);  // but it wasn't ... what gives? 
      $this-&gt;baz_changed = TRUE;
    }
  }
}

$sc = new SubClass();
$sc-&gt;foo = 1;
print "\n\$sc-&gt;foo = $sc-&gt;foo\n";
$sc-&gt;baz = 5;
print "\$sc-&gt;baz = $sc-&gt;baz\n";
?&gt;
</code></pre>

<p>I get the following results are not as I would have expected:</p>

<pre><code> $sc-&gt;foo = 1


 this-&gt;data BEFORE SET:  Array (
     [foo] =&gt; 1
     [bar] =&gt; 0
     [baz] =&gt; 0 )


 this-&gt;baz:  0

 PASSED baz:  5

 baz AFTER SET:  5

 DATA ARRAY:  Array (
     [foo] =&gt; 1
     [bar] =&gt; 0
     [baz] =&gt; 0 ) $sc-&gt;baz = 5
</code></pre>

<p>As you can see, it appears that baz is set but it never gets set in the data array.  Can anyone explain why and how to fix this?</p>

<p>EDIT: Fixed formatting of the results and adding more context to this code section because stackoverflow is complaining I do not have enough.</p>

<p>EDIT: Just noticed that at the end it says $sc->baz = 5.  But the data array isn't updated.  This is not expected I would rather that the data array version of baz were updated.  Instead of a new instance variable created in SubClass.</p>
