2

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}");
3
  • 1
    Enable your diagnostics, you get a big fat error message telling you exactly what's wrong. Commented Oct 10, 2011 at 15:26
  • Can you post the result of print_r($funcao); ? Commented Oct 10, 2011 at 15:27
  • Array ( [0] => c [1] => ola ) It now works with the call_user_func_array($funcao[0], array($funcao[1])); Commented Oct 10, 2011 at 15:39

3 Answers 3

4
call_user_func_array($funcao[0], $funcao[1]); 

=>

call_user_func_array($funcao[0], array($funcao[1]));
Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

3

call_user_func_array() expects the second parameter to be an array. Use call_user_func if you know the number of parameters.

2 Comments

can't do, I want this to be dynamic
Then use call_user_func_array().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.