1

Im trying to call a function dynamically, using call_user_func_array, but the issue I'm facing is that if the function returns boolean,Parameter variables are stored in an array, but if the function returns a string it will work fine

call_user_func_array() expects parameter 1 to be a valid callback, function 'equal' not found or invalid function name not included in ...

$param = array (
   0 => Jill
   1 => Jack
);

echo call_user_func_array("equal", $param);

function equal($str, $str_2) {
     if ($str==$str_2) {
         return true;
     } else {
         return false;
     }
}
10
  • they are in same place or equal is included? Commented Aug 22, 2012 at 8:05
  • in other place, but calling functions that return a string works well . Commented Aug 22, 2012 at 8:07
  • He meant: Do you include the file contain equal() before you call call_user_func_array()? Commented Aug 22, 2012 at 8:09
  • You say "it will produce an array", but then copy an error message saying that the function could not be found, which would make it return NULL, and demonstrate with echo, which would be an odd choice for a boolean or an array. Does the code as you've posted it actually reproduce the error for you? Commented Aug 22, 2012 at 8:15
  • 1
    Your array() syntax is wrong, but that shouldn't cause this error. Jack and Jill need to be in quotes, and you need a comma between them. Commented Aug 22, 2012 at 8:35

1 Answer 1

2

I tried your script. it is working and returning "false". Just use var_dump() instead of echo to test it. And if equal() is returning array then array is also returned. no errors for me.

Sign up to request clarification or add additional context in comments.

1 Comment

Works for me, too, once I fix the array syntax problems.

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.