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

  • SEARCH
  • Home
  • 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 8584787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:51:15+00:00 2026-06-11T21:51:15+00:00

When there is a function that requires a number of parameters to be passed,

  • 0

When there is a function that requires a number of parameters to be passed, such as seven parameters, which is the better practice:

function foo($par1, $par2, $par3, $par4, $par5, $par6, $par7)
{
}

or

function foo(array $args)
{
}

Where in the second example $args would an array with the parameters as elements.

I have been inconsistently using both methods.

The disadvantage to using the first method is that if you get order of a parameter wrong, you’re screwed (and it could be really hard to debug because it’s not always obvious). This is the advantage of using the array method.

The advantage (IMHO) of using the first type is that a good PHP editor such as PhpStorm will show you the names of the parameters as you are typing the function, which is easier than going to the function to see what parameters need to be passed in an array.

Appreciate your advice.

  • 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-06-11T21:51:16+00:00Added an answer on June 11, 2026 at 9:51 pm

    Theoretically, each parameter should encompass a logical whole. Collections are meant to represent a collection of values, not an aggregate of method parameters; the individual parameters should be passed separately to clearly indicate the purpose of the method.

    Practically, when passing parameters in an array, you have to do a ton of manual checks to ensure that correct parameters have been passed. You can avoid pretty much any ambiguity by giving your parameters clear, logical names (and typehints where possible). Also, as a comment already stated, if a method takes 7 parameters, it’s probably ripe for some refactoring.

    Edit: if your method/function does accept a set of vaguely defined “options” that affect what the code does only in a minor way, consider using the Symfony OptionsResolver component, to greatly ease the validation of your options array.

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

Sidebar

Related Questions

In Javascript is there a function that returns the number of times that a
I need to programmatically get the number of arguments that a function requires. With
I'm writing a Java application which requires a number of resource files (there will
Is there any function that does the inverse operation of array_diff() ? I mean,
Is there a function that can truncate or round a Double? At one point
Is there a function that tells what class you are extending? Like function_exists? I
Is there a function that takes 1,2,3 and returns 3,1,2 respectively and vice-verse. eg:
Is there some function that returns the parent directory of a file in Perl?
Is there a function that can round a float in Fsharp? Something like round(3.21156,3)
Is there any function that do the opposite job of QString::split() . I mean

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.