i have a class test that initiates a variable and register some anonymous functions. a function to display the variable testvar and another anonymous function to replace the variable with another variable. The problem is, wenn i call display the second time, the result is a variable but it should be another variable. I hope you understand the example and thank you very much.
class test {
private $functions = array();
private $testvar;
function __construct() {
$this->testvar = "a variable";
$this->functions['display'] = function($a) { return $this->display($a); };
$this->functions['replace'] = function($options) { return $this->replace($options); };
}
private function display($a) {
return $this->$a;
}
private function replace($options) {
foreach($options as $a => $b) {
$this->$a = $b;
}
}
public function call_hook($function, $options) {
return call_user_func($this->functions[$function], $options);
}
}
$test = new test();
echo $test->call_hook("display","testvar");
$test->call_hook("replace",array("testvar","another variable"));
echo $test->call_hook("display","testvar");