Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all arguments passed to function (vs. optional only $args)

$args returns only optional arguments. How can I get all function parameters?

like image 316
alex2k8 Avatar asked Apr 23 '09 12:04

alex2k8


People also ask

How do you pass all arguments to a function?

Within any function, you can use the arguments variable to get an array-like list of all of the arguments passed into the function. You don't need to define it ahead of time. It's a native JavaScript object. You can access specific arguments by calling their index.

How can I pass optional or keyword parameters from one function to another?

Users can either pass their values or can pretend the function to use theirs default values which are specified. In this way, the user can call the function by either passing those optional parameters or just passing the required parameters. Without using keyword arguments. By using keyword arguments.

How can you get the total number of arguments passed?

length property provides the number of arguments actually passed to a function. This can be more or less than the defined parameter's count (see Function. length ).

How do I make function arguments optional in Python?

You can assign an optional argument using the assignment operator in a function definition or using the Python **kwargs statement. There are two types of arguments a Python function can accept: positional and optional. Optional arguments are values that do not need to be specified for a function to be called.


1 Answers

$PSBoundParameters gets you all the parameters that were "bound" along with the bound values in a hashtable, it doesn't get you the optional/extra arguments. That is what $args is for. AFAICT the only way to get what you want is to combine the two:

$allArgs = $PsBoundParameters.Values + $args 
like image 148
Keith Hill Avatar answered Oct 03 '22 23:10

Keith Hill