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 8809841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:58:38+00:00 2026-06-14T02:58:38+00:00

I have dilemma on the format of method parameters for a function in PHP

  • 0

I have dilemma on the format of method parameters for a function in PHP (could be any language). The following are the two candidates

Candidate 1:


function foo($param1,$param2,$param3,....$paramN) 

and

Candidate 2:


function foo ($arr) {
   $param1 = $arr['param1'];
   $param2 = $arr['param2'];
   $param3 = $arr['param1'];
   ...
   ...
   ...
   $paramN = $arr['paramN'];
}

I am leaning towards candidate 2 at the moment because I have couple of methods which have many parameters. But, I am also concerned that if I go on the path of Candidate 2, then my code has the risk to become unreadable and not easily maintainable. While Candidate 2 is also very enticing because now the order of the params becomes irrelevant (hence the method signature) but I am afraid debugging would become a pain in the butt.

So which is the recommended way? Which candidate to choose and why?

  • 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-14T02:58:40+00:00Added an answer on June 14, 2026 at 2:58 am

    Lots of parameters are never nice to handle, I would personally opt for candidate 2 because it is more extensible. You can compensate for the “mess” with a validation logic that ensures, that all required parameters are set correctly.

    The – in my opinion – best way is to refactor your code and split the method in several, maybe chainable parts so the complexity is reduced.

    What might also be a nice option is to use Value Objects (or sometimes also Data Transfer Objects), to pass all the parameters in a sort of “container”. In this way, it’s ensured that only valid data can be passed, because the Value Object iself cares for its contents.

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

Sidebar

Related Questions

I have following dilemma: ob_start('processBuffer'); function processBuffer($buffer){ $betterBuffer = SomeClass::doSomething($buffer); return $betterBuffer; } function
I have the following dilemma with two elements (menu items) that I need to
I have a dilemma with this one. With the following code I am able
I have a dilemma, and I could really use some advice. I am building
I have a dilemma, I have two UIPickerViews which show when two distinct views
I have a very concrete dilemma right now. Given the following models: class Message
I have the next round up dilemma: hn = 143; label6.Text = string.Format({0} mm,
So I have a dilemma. I need to compare two C-style strings and I
I have the following dilemma, I have an Android Application that POST a request
Here's my dilemma - I have a two-column list of elements (styled <div> s)

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.