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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:00:47+00:00 2026-05-19T22:00:47+00:00

I have a search function that queries the database and has ~15 optional parameters.

  • 0

I have a search function that queries the database and has ~15 optional parameters. Obviously this is not pretty and calling it is a bit of a mess. PHP does not allow overloading methods so I’ve just been creating huge function signatures.

Elsewhere I’ve seen suggestions such as creating a parameter class: Disadvantages of using a lot of parameters

But this seems too heavy. I could pass in an associative array, but while this reduces the number of parameters I believe it is less easy to follow as there is no built in documentation stating what keys should exist in the array.

Is there any other way to handle this gracefully? Typically in other languages I would have a really ugly private method that takes up to a dozen parameters and then create public methods of the same name which accept a subset of those parameters and internally call the private method.

  • 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-19T22:00:48+00:00Added an answer on May 19, 2026 at 10:00 pm

    In PHP, you can use associative array:

    someFunction(array(
        "a" => 3243,
        "b" => 2354,
        "c" => 33453,
        "d" => 324353,
        "e" => 321243,
        "f" => 321243,
        "g" => 312243,
        "h" => 321243,
    ))
    

    Or properties of the object that the function is being called on (if it makes sense). PHPMailer send mails like this:

    // instantiate the class
    $mailer = new PHPMailer();
    
    // Set the subject
    $mailer->Subject = 'This is a test';
    
    // Body
    $mailer->Body = 'This is a test of my mail system!';
    
    // Add an address to send to.
    $mailer->AddAddress('foo@host.com', 'Eric Rosebrock');
    
    if(!$mailer->Send())
    {
        echo 'There was a problem sending this mail!';
    }
    

    And it has many more optional parameters. It could as well use a method with hundred parameters, but this is much more readable.

    EDIT: These solutions also better support optional parameters. In case of properties it is straightforward, in case of associative array, you can merge the array with array of default values.

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

Sidebar

Related Questions

I have a pagination function that I use for my database search that limits
I have a search program that will be looking at a database from a
I have a search function that performs basic filtering in a Rails 3 application
if i have a search function for my site and i want the user's
I have a problem using the Java search function in Eclipse on a particular
I have search in MSDN and I can't figure where are the POST parameters
I have a search box that doesn't have a submit button, I need to
I have a search query that I'm inheriting and attempting to optimize. I am
I have a search page that is tasked with searching 3.5 million records for
I have a web application with lots of data, and a search/filter function with

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.