I have a class and I'm trying to call a function from outside of it that calls a dynamic function inside the class using call_user_func_array(). I think it's a problem with call_user_func_array not checking the local functions first before looking globally because if I put the functions in the file I call validate_data from it works. How can I get around this? Is there another function I can use to call dynamic functions? To make more sense here's my code and the errors I get:
function validate_data($data, $val_array) {
$error = array();
foreach ($val_array as $var => $val_seq)
{
if (!is_array($val_seq[0]))
{
$val_seq = array($val_seq);
}
foreach ($val_seq as $validate)
{
$function = array_shift($validate);
array_unshift($validate, $data[$var]);
if ($result = call_user_func_array('validate_' . $function, $validate))
{
$error[] = strtoupper($var) . '_' . $result;
}
}
}
return $error;
}
I use this line to call validate data:
$formValidation->validate_data($data, $val_array);
The errors I get are:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_string' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_username' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_string' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_password' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_string' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_string' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_string' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_numeric' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'validate_numeric' was given in C:\Apache\htdocs\toss\classes\formvalidation.class.php on line 45