title: PHP how to detect the change of variable?
body: <p>Is PHP exists a function that detect the change of variable?
  That is something like this:</p>
  
  <pre><code>//called when $a is changed.
  function variableChanged($value) {
      echo "value changed to " . $value;
  }
  
  $a = 1;
  //attach the variable to the method.
  $a.attachTo("variableChanged");
  $a = 2;
  $a = 3;
  
  //expected output:
  //value changed to 2
  //value changed to 3
  </code></pre>
  
  <p>I know that it is easy to achieve if I use the "setter" method. But since I am working on some existing codes, I am not able to modify them. Can somebody tell me how to achieve my purpose? Thanks.</p>