You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I'm using the Go! AOP framework ("^3.0") in my Laravel project ("^8.40"), however, I'm running into the following exception thrown from the Laminas ParameterGenerator class when the following line is called:
It seems that the $defaultValue passed to the constructor of the ParameterGenerator in line 62 really needs to be null for optional and non-variadic parameters. This is not the case due to:
I also have one case where I have a controller method with a default parameter value, this is a non-variadic parameter as well and runs into the same Exception. However, I was able to resolve both issues by explicitly setting the default value after the setVariadic call instead of doing it before. This has the reason that setVariadic is checking whether its default value attribute is set (and throws an Exception if thats the case) before it actually sets the variadic attribute to true or false.
Here is a snippet of what I have changed:
// ...$defaultValue = null;
// Move default value detection code to the bottom (after setVariadic)$parameterTypeName = null;
if (!$useTypeWidening && $reflectionParameter->hasType()) {
$parameterReflectionType = $reflectionParameter->getType();
if ($parameterReflectionTypeinstanceof ReflectionNamedType) {
$parameterTypeName = $parameterReflectionType->getName();
} else {
$parameterTypeName = (string) $parameterReflectionType;
}
}
$generatedParameter = newParameterGenerator(
$reflectionParameter->getName(),
$parameterTypeName,
$defaultValue, // We are passing null here for now$reflectionParameter->getPosition(),
$reflectionParameter->isPassedByReference()
);
$generatedParameter->setVariadic($reflectionParameter->isVariadic());
// The isset($this->defaultValue) wont throw a Exception now// Check if parameter is non-variadic and call setDefaultValue if(!$reflectionParameter->isVariadic()){
if ($reflectionParameter->isDefaultValueAvailable()) {
$defaultValue = newValueGenerator($reflectionParameter->getDefaultValue());
} elseif ($reflectionParameter->isOptional()) {
$defaultValue = newValueGenerator(null);
}
if($defaultValueinstanceof ValueGenerator) {
$generatedParameter->setDefaultValue($defaultValue);
}
}
// ...
Hope this can be of use to anyone running into the same issue. Let me know if further information are required for reproduction - the Laravel project that I'm working on is pretty much an empty project with one HTTP controller.
Kind regards,
Tolga
The text was updated successfully, but these errors were encountered:
Hi!
I'm using the Go! AOP framework (
"^3.0"
) in my Laravel project ("^8.40"
), however, I'm running into the following exception thrown from the LaminasParameterGenerator
class when the following line is called:https://github.com/laminas/laminas-code/blob/17fd2af36804f3f61788573cb70196454d6ee1d8/src/Generator/ParameterGenerator.php#L260
framework/src/Proxy/Part/FunctionParameterList.php
Line 66 in 501d013
It seems that the
$defaultValue
passed to the constructor of theParameterGenerator
in line 62 really needs to benull
for optional and non-variadic parameters. This is not the case due to:framework/src/Proxy/Part/FunctionParameterList.php
Line 46 in 501d013
I also have one case where I have a controller method with a default parameter value, this is a non-variadic parameter as well and runs into the same Exception. However, I was able to resolve both issues by explicitly setting the default value after the
setVariadic
call instead of doing it before. This has the reason thatsetVariadic
is checking whether its default value attribute is set (and throws an Exception if thats the case) before it actually sets the variadic attribute to true or false.Here is a snippet of what I have changed:
Hope this can be of use to anyone running into the same issue. Let me know if further information are required for reproduction - the Laravel project that I'm working on is pretty much an empty project with one HTTP controller.
Kind regards,
Tolga
The text was updated successfully, but these errors were encountered: