title: PHP override function of a single instance
body: <p>In javascript i know it is possible to simply override a class-method of a single instance but I am not quite sure how this is managable in PHP.
  Here is my first idea:</p>
  
  <pre><code>class Test {
      public $var = "placeholder";
      public function testFunc() {
          echo "test";
      }
  }
  
  $a = new Test();
  
  $a-&gt;testFunc = function() {
      $this-&gt;var = "overridden";
  };
  </code></pre>
  
  <p>My second attempt was with anonymous function calls which unfortunately kills the <strong>object</strong> scope...</p>
  
  <pre><code>class Test {
      public $var = "placeholder";
      public $testFunc = null;
      public function callAnonymTestFunc() {
          $this-&gt;testFunc();
      }
  }
  
  $a = new Test();
  
  $a-&gt;testFunc = function() {
      //here the object scope is gone... $this-&gt;var is not recognized anymore
      $this-&gt;var = "overridden";
  };
  
  $a-&gt;callAnonymTestFunc();
  </code></pre>