Home >Backend Development >PHP Tutorial >Analyze the use of func_num_args and func_get_args functions_PHP tutorial
func_num_args function function – returns the number of parameters passed to the function, its syntax is as follows : int func_num_args (void).
Description: Returns the number of parameters passed to the currently defined function. func_get_arg() will generate a warning if this function is called from outside the function definition.
func_num_args( ) can be used in conjunction with func_get_arg( ) and func_get_args( ) to allow user-defined functions to accept variable-length argument lists. Among them, func_get_arg() returns items from the parameter list, its syntax: int func_get_arg (int arg_num), returns the arg_numth parameter of the parameter list that defines the function, and its parameters start from 0. And calling this function outside the function definition will generate a warning; and when arg_num is greater than the number of parameters actually passed by the function, a warning will also be generated and FALSE will be returned.
The difference between the func_get_args() function and the func_get_arg() function is that the func_get_args() function returns an array, and each element of the array is equivalent to the number of parameter columns of the current user-defined function.
When we build a PHP class, flexibly using these three functions can achieve very ideal results. For example, when creating a class that links PHP and MYSQL, can write the following code: