I want to get all parameters (passed or not) from a function.
Example:
You can accomplish this using the ReflectionFunction function class.
function foo($a, $b=1)
{
$arr = array();
$ref = new ReflectionFunction(__FUNCTION__);
foreach($ref->getParameters() as $parameter)
{
$name = $parameter->getName();
$arr[$name] = ${$name};
}
print_r($arr);
// ...
}
Calling the function:
foo(1);
Output:
Array
(
[a] => 1
[b] => 1
)
Demo