Laminas\Code\Generator\PromotedParameterGenerator#fromParameterGeneratorWithVisibility are losing nullable flag of such parameter.
Current behavior
class Test {
public function __construct(
protected ?int $value
) {
}
}
$parameterReflection = new ParameterReflection([Test::class, '__construct'], 0);
$parameterGenerator = PromotedParameterGenerator::fromReflection($parameterReflection);
echo $parameterGenerator->generate();
will echo protected int $value, nullable flag is lost.
public static function fromParameterGeneratorWithVisibility(ParameterGenerator $generator, string $visibility): self
{
$name = $generator->getName();
$type = $generator->getType(); // <----- this would return "bare" type, without modifiers
Unfortunately, there are no way to get nullable flag from TypeGenerator at all for now. Unsurprisingly it get lost on the way.
Bug Report
Summary
Laminas\Code\Generator\PromotedParameterGenerator#fromParameterGeneratorWithVisibility are losing nullable flag of such parameter.
Current behavior
will echo
protected int $value
, nullable flag is lost.How to reproduce
Use snippet above.
Expected behavior
Code above should echo
protected ?int $value
.Additional information
https://github.com/laminas/laminas-code/blob/169123b3ede20a9193480c53de2a8194f8c073ec/src/Generator/PromotedParameterGenerator.php#LL73C51-L73C51
Unfortunately, there are no way to get nullable flag from TypeGenerator at all for now. Unsurprisingly it get lost on the way.