I'm about to use func_get_args
for reading additional arguments of a function call.
How does this affect the performance? Should I rather use an array for passing additional arguments instead of reading them with the function above?
func_get_args(): array. Gets an array of the function's argument list. This function may be used in conjunction with func_get_arg() and func_num_args() to allow user-defined functions to accept variable-length argument lists.
To get the number of arguments that were passed into your function, call func_num_args() and read its return value. To get the value of an individual parameter, use func_get_arg() and pass in the parameter number you want to retrieve to have its value returned back to you.
The func_num_args() function can return the number of arguments passed into current user-defined function. This function can generate a warning if called from outside of a user-defined function.
func_get_args( ) returns an array of all parameters provided to the function, func_num_args( ) returns the number of parameters provided to the function, and func_get_arg( ) returns a specific argument from the parameters.
Unless you are using it in mass quantities, no single function will make that much difference. You could always check how long it takes to call by using microtime()
before and after the call, but I don't think you'll find anything interesting.
Go ahead and use it if you'd like.
I'd be more worried about making sure other programmers understand how the function works and knowing that they can pass any number of arguments to the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With