func_get_arg

Description

Gets the specified argument from a user-defined function's argument list.

This function may be used in conjunction with
func_get_args() and func_num_args()
to allow user-defined functions to accept variable-length argument lists.

Parameters

arg_num

The argument offset. Function arguments are counted starting from
zero.

Return Values

Returns the specified argument, or FALSE on error.

Changelog

Version

Description

5.3.0

This function can now be used in parameter lists.

5.3.0

If this function is called from the outermost scope of a file
which has been included by calling include
or require from within a function in the
calling file, it now generates a warning and returns FALSE.

Errors/Exceptions

Generates a warning if called from outside of a user-defined function, or
if arg_num is greater than the number of arguments
actually passed.

Notes

Note:

Because this function depends on the
current scope to determine parameter details, it cannot be used as a
function parameter in versions prior to 5.3.0. If this value must be passed, the results should be assigned
to a variable, and that variable should be passed.

Note:

If the arguments are passed by reference,
any changes to the arguments will be reflected in the values returned by this function.

Note:
This function returns a copy of the passed arguments only, and does not
account for default (non-passed) arguments.

I actually think that there is need for such "do absolutely everything" functions. I use them mostly as tools for rapid prototyping.And there is a method with which you may be able to pass several strings to a function: ereg();Another use for such functions is to create little code snippets for other people out there. They won't have to edit the function any longer if they do not use a parameter. They just don't name it when calling the function.This results in allrounder functions that are very robust in their use.Normally you just have a little code snippet (e.g. ip-blocking snippets). Through this type of programming you have whole functions.

func_get_arg() returns a *copy* of the argument, to my knowledge there is no way to retrieve references to a variable number of arguments.

I have a module system in my game at http://lotgd.net where I'd like to be able to pass a variable number of arguments to functions in a module, and pass them by reference if the module asks for it by reference, but you can't accept optional parameters as references, nor can you retrieve the reference on a variable number of arguments. Looks like my modules will have to do with out the ability to accept parameters to their functions by reference.