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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:51:22+00:00 2026-06-16T03:51:22+00:00

Silex PHP microframework does a callback injection based on the automatic type hinting. For

  • 0

Silex PHP microframework does a callback injection based on the automatic type hinting. For example, in Silex one can supply a Closure argument with arbitrary arguments like so:

$app->get('/blog/show/{postId}/{commentId}', function ($commentId, $postId) {
    //...
});
$app->get('/blog/show/{id}', function (Application $app, Request $request, $id) {
    //...
});
// following works just as well - order of arguments is not important
$app->get('/blog/show/{id}', function (Request $request, Application $app, $id) {
    //...
});

How do I do this? I’m not interested in getting parameter types as strings. I am looking for a “no strings” fully automatic solution. In other words,

  1. For a number of possible arguments:

    $possible_arguments = [
        new Class_A(), 
        new Class_B(), 
        new Class_C(), 
        new Another_Class, 
        $some_class
    ];
    
  2. For a closure with any number of arbitrary arguments, that can only include those defined above only once:

    $closure = function (Class_B $b, Another_Class, $a) {
        // Do something with $a and $b
    };
    
  3. I need to get only matching arguments in order to call the closure with them:

    // $arguments is now [$possible_arguments[1], $possible_arguments[3]]
    call_user_func_array($closure, $arguments);
    
  • 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-16T03:51:24+00:00Added an answer on June 16, 2026 at 3:51 am

    Indeed they’re using Reflection, specifically in the ControllerResolver class.

    If you let me to simplify to include only one case of Closure and only object-type arguments:

    $availableArguments = array($a, new B(), $c);
    $arguments = array();
    $reflection = new \ReflectionFunction($callback);  // $callback is a Closure
    foreach ($reflection->getParameters() as $param) {
        if ($paramClass = $param->getClass()) {
            foreach ($availableArguments as $proposedArgument) {
                if ($paramClass->isInstance($proposedArgument)) {
                    $arguments[] = $proposedArgument;
                    break;
                }
            }
        }
    }
    call_user_func_array($callback, $arguments);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application file: <?php // /src/app.php require_once __DIR__ . '/../lib/vendor/Sensio/silex.phar'; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response;
I'm using Silex, and need to alter a Twig file based on the location
I'm using Silex and can't use the is_granted function in a template. I can't
I have a PHP application, using symfony2, silex, and the AWS DynamoDB SDK. It's
I have this simple code: <?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->get('/hello', function()
So, i'm working with Silex microframework and i'm curious about the correct PHPDoc way
I put phpexcel to /silex/vendor/ index.php: <?php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->register(new
I'm trying to build a silex application. My file structure is: ROOT/ /App/ /Controller/{IndexController.php}
i've got a project in php-silex, but i beging with this framework. I create
With Silex (the PHP micro framework), it's possible to give names to existing controllers,

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.