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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:43:06+00:00 2026-05-24T00:43:06+00:00

In C#, there is a new feature coming with 4.0 called Named Arguments and

  • 0

In C#, there is a new feature coming with 4.0 called Named Arguments and get along well with Optional Parameters.

private static void writeSomething(int a = 1, int b = 2){
   // do something here;
}

static void Main()
{
   writeSomething(b:3); // works pretty well 
}

I was using this option to get some settings value from users.

In PHP, I cannot find anything similar except for the optional parameters but I am accepting doing $.fn.extend (jQuery) kind of function :

function settings($options)
{
   $defaults = array("name"=>"something","lastname"=>"else");
   $settings = array_merge($defaults,$options);
}

settigs(array("lastname"=>"John");

I am wondering what kind of solutions you are using or you would use for the same situation.

  • 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-24T00:43:07+00:00Added an answer on May 24, 2026 at 12:43 am

    As you found out, named arguments don’t exist in PHP.

    But one possible solution would be to use one array as unique parameter — as array items can be named :

    my_function(array(
        'my_param' => 10, 
        'other_param' => 'hello, world!', 
    ));
    

    And, in your function, you’d read data from that unique array parameter :

    function my_function(array $params) {
    
        // test if $params['my_param'] is set ; and use it if it is
        // test if $params['other_param'] is set ; and use it if it is
        // test if $params['yet_another_param'] is set ; and use it if it is
        // ...
    
    }
    

    Still, there is one major inconvenient with this idea : looking at your function’s definition, people will have no idea what parameters it expects / they can pass.

    They will have to go read the documentation each time they want to call your function — which is not something one loves to do, is it ?

    Additionnal note : IDEs won’t be able to provide hints either ; and phpdoc will be broken too…

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

Sidebar

Related Questions

(I'm developing in Python 3.1, so if there's some shiny new 3.x feature I
In Ninject3 there's a new .ToConstructor feature . As described, it helps to strongly-type
I've seen there is a new feature in Jira 4.3, issue status history, but
Knowing that from Xcode4 and LLVM 2.0 there is the new feature @syntesize by
There are a lot of new features that came with the .Net Framework 3.5.
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at
Particularly, what is the best snippets package out there? Features: easy to define new
Is there a new version of XML out? If so when was it released
Is there a new way to connect to MySQL from Python with Mac OS
Does anyone know if there are new binaries for the castle logging facility using

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.