Closed gnanet closed 2 years ago
Sorry for this late answer. Holidays.
Try to use func_get_args() inside your predefined function. So you can have a variable number of arguments: https://www.php.net/manual/en/function.func-get-args.php
Not tested code:
function my_func() {
// Get all the function args without defining them inside the function head
$arg_list = func_get_args();
// Print all function args
print_r($arg_list);
// Return your content
if(count($arg_list)){
return 'This is a working pre-defined function. Parameter: '.$arg_list[0];
} else {
return 'This is a working pre-defined function. Parameter: Nor args given';
}
}
Route::add('/', 'my_func');
Route::add('/browse/(.*)', 'my_func');
Looked at the examples, and reading the php docs about call_user_func_array i was missing the example, how it can be used with a pre-defined function, including parameters.
I would suggest a rather extensive example: