Closed bartvanhoutte closed 4 years ago
Method getArguments()
returns only arguments that was given to that function.
If you need to access default values, you could do this by accessing $invocation->getMethod()->getParameters()
and reflect default values from method signature:
$defaultArgs = [];
foreach ($invocation->getMethod()->getParameters() as $argInfo) {
if ($argInfo->isDefaultValueAvailable()) {
$defaultArgs[$argInfo->getPosition()] = $argInfo->getDefaultValue();
}
}
$args = $invocation->getArguments() + $defaultArgs;
But be aware, that refection could be slow, so it is your responsibility to cache default argumenta per each function/method to speed up advice invocation.
Perfect, thank you.
If you have a function that defines a parameter with a default value...
public function foo(array $bar = [])
and you call it without passing a value...
->foo();
MethodInvocation->getArguments() is empty.
It would be nice for getArguments() to contain the default value. Unless you want to know that no value was passed ofcourse :thinking: