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:
class Test {
public $var = "placeholder";
public function testFunc() {
echo "test";
}
}
$a = new Test();
$a->testFunc = function() {
$this->var = "overridden";
};
My second attempt was with anonymous function calls which unfortunately kills the object scope...
class Test {
public $var = "placeholder";
public $testFunc = null;
public function callAnonymTestFunc() {
$this->testFunc();
}
}
$a = new Test();
$a->testFunc = function() {
//here the object scope is gone... $this->var is not recognized anymore
$this->var = "overridden";
};
$a->callAnonymTestFunc();