Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing arguments where registering Lazy services #369

Open
blurp1478963 opened this issue Sep 24, 2017 · 2 comments
Open

Passing arguments where registering Lazy services #369

blurp1478963 opened this issue Sep 24, 2017 · 2 comments

Comments

@blurp1478963
Copy link

Hi,

It's now impossible to do something like

    $app->register('myfunction', function($arg1, $arg2) {
        var_dump($arg1); // return NULL
    })

$args are not passed to function

I suggest to change App.php, at line 95 from:
$instance = $closure();
to
$instance = call_user_func_array($closure,func_get_args());

Giving the possibility to use $app->myfunction("argument1","argument2");

Thks by advance!

@ddv88
Copy link

ddv88 commented Sep 29, 2017

You should use closure.

$app->register('myfunction', function($result) use ($arg1, $arg2) {
        var_dump($arg1);
    })

$result will be returning value of your function.

@blurp1478963
Copy link
Author

Doesn't work...
My goal is to pass $arg1 and $arg2 dynamically when I will call this service:

$klein->respond('GET', '/', function ($request, $response, $service, $app) {
    return $app->myfunction('foo',['foo','bar']);
});

thanks for advises,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants