Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: func_get_args performance?

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?

like image 686
Daniel Avatar asked Aug 20 '10 15:08

Daniel


People also ask

What is Func_get_args?

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.

How do you get the number of arguments passed to a PHP function?

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.

What is the function Func_num_args () used for?

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.

Which of the following function returns an array of all parameters provided to 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.


1 Answers

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.

like image 140
Tyler Carter Avatar answered Nov 15 '22 05:11

Tyler Carter