In Python and others, there's special syntax for variable length argument lists:
def do_something(*args):
# do something
do_something(1, 2, 3, 4, 5, ...) # arbitrarily long list
I was reading the PHP manual, and it said this:
PHP 4 and above has support for variable-length argument lists in user-defined functions. This is really quite easy, using the func_num_args(), func_get_arg(), and func_get_args() functions.
No special syntax is required, and argument lists may still be explicitly provided with function definitions and will behave as normal.
I get the first part. You can pass as many arguments as you'd like to a function that takes no arguments, then get them as an array using func_get_args()
, etc. I don't really get what the second part is saying, though.
So, my question is, is there some special syntax for variable length arguments, or some best practice that I don't know about? The approach that the manual suggests seems kludgey at best and makes your function seem like it's taking no arguments (unless I'm doing it wrong). Should I not be trying to use this language feature at all?