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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:54:35+00:00 2026-06-13T13:54:35+00:00

Lets say I define class with method like this: class Test { public function

  • 0

Lets say I define class with method like this:

class Test {
    public function doStuff($a, $b, $c) {
    // -- Do stuff --
    }
}

Is it possible to use this method but with arguments in different order, like this:

$test = new Test();
$test->doStuff($b, $c, $a);

They would have the same names, but just different order.

I see Symfony2 can do it with its dispatcher, you can use arguments in any order you want.
Link: Symfony2 controller can do it

The question is, how to make this work? How can Symfony2 invoke appropriate action controller, that can then accept arguments in any order you like?

Edit:
I cant use arrays, and I do know that php does not use named arguments. But somehow Symfony2 manage to do it.

  • 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-13T13:54:37+00:00Added an answer on June 13, 2026 at 1:54 pm

    I think you are misunderstanding what Symfony is saying. You can’t pass the arguments to the controller action in any order, it has to be in a specific order. What they are doing that is dynamic, however, is figuring out what order your routing parameters are in inside the function definition.

    For example we define a route:

    pattern:      /hello/{first_name}/{last_name}
    defaults:     { _controller: AcmeHelloBundle:Hello:index, color: green }
    

    In the route, the parameters are named first_name, last_name, and color.

    What they are saying, is that it doesn’t matter what order you use for the parameters in the action.

    Each of the following are equivalent:

    public function indexAction($first_name, $last_name, $color) {...}
    public function indexAction($color, $last_name, $first_name) {...}
    public function indexAction($last_name, $color, $first_name) {...}
    

    Since your arguments are named the same as the parameters in the route, Symfony figures out what the correct order of the arguments is based on your definition.

    If you were to call the following action manually:

    public function indexAction($first_name, $last_name, $color)
    

    Then the arguments still must be passed in as $first_name, $last_name, $color and not in any other order. Using a different order would just associate the wrong values with the arguments. Symfony just doesn’t care what order you define your function in since it determines the order because your routing parameters must be named the same thing as your method arguments.

    Hopefully that clears up the confusion.

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

Sidebar

Related Questions

Let's say that I've defined a dependency like this: public class MySampleClass {public static
Lets say I have a class like this: Class User { var $id var
Let's say that I define a ClassA , that implements NSCoding protocol (this class
Lets say I have a parent Class: Class Parent{ public: virtual void doSomething(){} }
I have a State class defined like this: Public Class State Public Property StateId
Let's say I got the class name with get_class($this) within an abstract class method.
Lets say I have model inheritance set up in the way defined below. class
Let's say I have defined the following class: public abstract class Event { public
Lets say I want to define 2 styles. .color_red { color: Red; } .banner
Lets say i have at least two lua script files. test1.lua test2.lua both define

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.