1

May I ask is there a PHP way to write a variable number of parameters to a function pointer?

For example (psuedocode)

$args = $request->get_args(); // get an array of arguments
$request->$func_pointer(foreach $args write $arg);

My objective is to allow the API user to write functions with fixed number of parameters. And later on pass the function name and the args which my API will execute on behalf.

Hope it is clear. Thank you.

1 Answer 1

3
call_user_func_array(array($request, $func_pointer), $args);

See Manual call_user_func_array() for further information.

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

1 Comment

Thanks! this must be the hidden gems that only comes with usage experience.

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.