Parse the use of func_num_args and func_get_args functions. Func_num_args function-return the number of parameters passed to the function. The syntax is as follows: intfunc_num_args (void ). Description: return the number of parameters passed to the current defined function. For the func_num_args function-return the number of parameters passed to the function, the syntax is as follows: int func_num_args (void ).
Note:Returns the number of parameters passed to the current defined function. If you call this function outside the function definition, func_get_arg () generates a warning.
Func_num_args () can be used in combination with func_get_arg () and func_get_args () to allow the user-defined function to accept the list of variable-length parameters. Func_get_arg () returns the item from the parameter list. Its syntax is int func_get_arg (int arg_num). It returns the arg_num parameter in the parameter list of the defined function. its parameter starts from 0. When you call this function outside the function definition, a warning is generated. when arg_num is greater than the number of parameters actually passed by the function, a warning is generated and FALSE is returned.
The difference between the func_get_args () function and func_get_arg () function is that the func_get_args () function returns an array. the elements of the array are equivalent to the number of parameter columns defined by the user.
When we build PHP classes, flexible use of these three functions can play a very ideal effect, for example, when creating a class with links to PHP and MYSQL,
You can write the following code:
The code is as follows:
Class mydb {
Private $ user;
Private $ pass;
Private $ host;
Private $ db;
Public function _ construct (){
$ Num_args = func_num_args ();
If ($ num_args> 0 ){
$ Args = func_get_args ();
$ This-> host = $ args [0];
$ This-> user = $ args [1];
$ This-> pass = $ args [2];
This-> connect ();
}
}
............ Omitted ............
?>
Callback-returns the number of parameters passed to the function. The syntax is as follows: int func_num_args (void ). Description: return the number of parameters passed to the current defined function. If it is...