title: PHP ignoring __set method inside the class
body: <p>I'm building a class with a number of input validations, and I've decided to place them inside a __set method (I'm not sure if this is proper form as I have limited OOP experience). This seems to work fine, throwing the proper errors when invalid values are passed from outside the class. However, if a variable is modified inside the class the _ _set method seems to be ignored alltogether.</p>
  
  <p>Any insight would be hugely appreciated</p>
  
  <pre><code>//RESULT:::::::::::::::::::::::::::::::
  // PASS: Testing : hello
  // PASS: Testing exception handling
  // __SET: Setting b to 123
  // PASS: Testing with valid value: 123
  // FAIL: Testing exception handling World2
  
  
  
   &lt;?php
  class Test {
          public $a;
          private $b;
  
          function __set( $key, $val ) {
  
                  switch( $key ) {
                          case 'b':
                                  if( !is_numeric( $val ) ) throw new Exception("Variable $b must be numeric");
                                  break;
                  }
  
                  echo ( "__SET: Setting {$key} to {$val}&lt;br/&gt;" );
                  $this-&gt;$key = $val;
          }
          function __get( $key ) { return $this-&gt;$key; }
          function bMethod() {
                  $this-&gt;b = "World2";
          }
  
  }
  
  $t = new Test();
  
  //testing a
  try {
          $t-&gt;a = "hello";
          echo "PASS: Testing $a: {$t-&gt;a}&lt;br/&gt;";
  } catch( Exception $e)  {
          echo "FAIL: Testing $a";
  }
  
  //testing b
  try {
          $t-&gt;b = "world";       
          echo "FAIL: Testing $b exception handling&lt;br/&gt;";
  } catch( Exception $e ){
          echo "PASS: Testing $b exception handling&lt;br/&gt;";
  }
  
  //testing b with valid value
  try  {
          $t-&gt;b = 123;
          echo "PASS: Testing $b with valid value: {$t-&gt;b}&lt;br/&gt;";
  } catch( Exception $e) {
          echo "FAIL: Testing $b";
  }
  
  //bypassing exception handling with method
  try {
          $t-&gt;bMethod("world");
          echo "FAIL: Testing $b exception handling {$t-&gt;b}&lt;br/&gt;";
  } catch( Exception $e ) {
          echo "PASS: Testing $b exception handling&lt;br/&gt;";
  }
  </code></pre>