tags:

views:

163

answers:

3

Hi,

is there a way to get the available arguments for a php function?

Example: I want to call function1($arg1, $arg2=null)

How can i find out a priori, before i call the function, the number of arguments this function takes, and if it's possible what arguments.

As you can clearly see i am dynamically calling functions

+12  A: 

ReflectionFunction

troelskn
Thank you. I had to juggle a bit more to get where i want but that's what i was looking for
Fotis
You're welcome. If, for some reason, you can't load the code into the runtime, you could also use `token_get_all` to parse the source code. It's probably not applicable to your situation, but just wanted to mention the option, in case some one else reads this and have that requirement.
troelskn
+1  A: 

You can use the following functions from inside the function that is being called to determine how many arguments were passed and to get their values. I'm not sure how you would check what arguments a function expects.

func_num_args()

func_get_arg()

func_get_args

Lawrence Barsanti
+1  A: 

Normally, via ReflectionFunction. However, PHP functions can use variable arguments and in that case it's impossible to tell.

Michael Borgwardt
func_get_args() gives you the arguments passed to a function. I think the question is how to find out the argument list for a given function
Tom Haigh
That's right Tom, it's exactly like that
Fotis