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;
     }
}
meWantToLearn
  • 1,691
  • 2
  • 25
  • 45
  • they are in same place or `equal` is included? – Mihai Iorga Aug 22 '12 at 08:05
  • in other place, but calling functions that return a string works well . – meWantToLearn Aug 22 '12 at 08:07
  • He meant: Do you include the file contain `equal()` _before_ you call `call_user_func_array()`? – KingCrunch Aug 22 '12 at 08: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? – IMSoP Aug 22 '12 at 08:15
  • edited it, I mean the parameters are stored in an array – meWantToLearn Aug 22 '12 at 08:27
  • 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. – Barmar Aug 22 '12 at 08:35
  • @Barmar that's a copy-paste of a print_r it's not meant to reproduce array syntax, just to show you what the array contains. – Mihai Stancu Aug 22 '12 at 08:38
  • What do you mean by "parameters are stored in an array"? What is that a `print_r()` of? The input to the function, or the output? – IMSoP Aug 22 '12 at 13:28
  • call_user_func_array , requires the parameters to be in an array – meWantToLearn Aug 22 '12 at 13:50
  • Yes. That's why it's called call_user_func_ARRAY. RTFM http://php.net/call_user_func_array http://uk.php.net/call_user_func – IMSoP Aug 22 '12 at 16:45

1 Answers1

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.

wormhit
  • 3,687
  • 37
  • 46