Reputation: 1477
first time trying to deal with this call_user_func_array, but something isn't working, since I get no response from the function, what can I be missing?
function _a_($id, $text) {
if($id == 'a') {
_b_();
if(substr($text, 0, 8) == "{source}") {
$campos = substr_replace($text, '', 0, 8);
$campos = substr($campos, 0, -9);
$funcao = explode(";", $campos);
print_r($funcao);
call_user_func_array($funcao[0], $funcao[1]);
}
} else {
echo $text."<br>";
}
}
function _b_() {
echo "b was fired<br>";
}
function _c_($some_text) {
echo "received a call<br>";
echo "inside function c: ".$some_text."<br>";
}
_a_("a", "{source}_c_;ola{/source}");
Upvotes: 2
Views: 3325
Reputation: 109
call_user_func_array($funcao[0], $funcao[1]);
=>
call_user_func_array($funcao[0], array($funcao[1]));
Upvotes: 4
Reputation: 14343
call_user_func_array() expects the second parameter to be an array. Use call_user_func if you know the number of parameters.
Upvotes: 3
Reputation: 476940
Say either this:
call_user_func($funcao[0], $funcao[1]);
Or this:
call_user_func_array($funcao[0], array($funcao[1]));
The latter form is only useful if you need to pass the arguments by reference; see the documentation for details.
Upvotes: 4