Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3667628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:01:29+00:00 2026-05-19T02:01:29+00:00

In Python and others, there’s special syntax for variable length argument lists: def do_something(*args):

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:01:30+00:00Added an answer on May 19, 2026 at 2:01 am

    Unlike Python’s * operator or C#’s params keyword, in PHP you don’t even have to specify the variable length arguments. As the second part starts off, “No special syntax is required.”

    As to the rest of the second paragraph: if you want to specify any required or unrelated arguments that come before the variable-length arguments, specify them in your function signature so your function can handle those. Then to get the variable-length arguments, remove the required variables from func_get_args(), like so:

    function func($required) {
        // Contains all arguments that come after $required
        // as they were present at call time
        $args = array_slice(func_get_args(), 1);
    }
    

    You don’t have to do this (you can still slice from func_get_args() and use its different elements accordingly), but it does make your code more self-documenting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there something like the Python descriptor protocol implemented in other languages? It seems
Python, C++, Scheme, and others all let you define functions that take a variable
I know with python and a couple other languages there is a way to
Is there a benefit to using one over the other? In Python 2, they
Is there an online Java book like Dive into Python for learning Python? Other
I have a series of Python classes in a file. Some classes reference others.
In Python (and others), you can incrementally process large volumes of data by using
There are a lot of web application frameworks out there, based in Java/Ruby/Python/PHP amongst
Are there any built-in libraries in Python or Numpy to generate random numbers based
Is there an equivalent of slime for python? For example, if I position the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.