I'm trying to make a system which handles supplied data and calls the functions assigned to them in an array with addHandler().
Code:
class Test {
public $arrHandlers = array();
public function addHandler($action, $function) {
$this->arrHandlers[$action] = $function;
}
public function handleData($data) {
$data = explode("/", $data);
$action = array_shift($data);
if(isset($this->arrHandlers[$action])) {
call_user_func_array($this->arrhandlers[$action], array($data));
}
}
}
function testFunc() {
echo implode(" ", func_get_args());
}
$obj = new Test();
$data = "egg/I/like/cheese";
$obj->addHandler("egg", "testFunc");
$obj->handleData($data);
What it outputs:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given on line 13
What I want it to output:
I like cheese