Possible duplicate:
PHP Reflection - Get Method Type of Parameter as String
The Silex PHP microframe performs a backlash based on an automatic type hint. For example, in Silex, you can provide a Closure argument with arbitrary arguments, for example:
$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 can I do it? I am not interested in getting parameter types as strings. I am looking for a fully automatic "no line" solution. In other words,
For a number of possible arguments:
$possible_arguments = [ new Class_A(), new Class_B(), new Class_C(), new Another_Class, $some_class ];
To close with any number of arbitrary arguments, which can include only those defined above, only once:
$closure = function (Class_B $b, Another_Class, $a) {
I need to get only matching arguments to cause a closure with them:
// $arguments is now [$possible_arguments[1], $possible_arguments[3]] call_user_func_array($closure, $arguments);
source share