diff --git a/src/PhpGenerator/Extractor.php b/src/PhpGenerator/Extractor.php index 7de301fe..50164ced 100644 --- a/src/PhpGenerator/Extractor.php +++ b/src/PhpGenerator/Extractor.php @@ -389,8 +389,9 @@ private function setupFunction($function, Node\FunctionLike $node): void $function->setReturnType($node->getReturnType() ? $this->toPhp($node->getReturnType()) : null); foreach ($node->getParams() as $item) { $visibility = $this->toVisibility($item->flags); + $isReadonly = (bool) ($item->flags & Node\Stmt\Class_::MODIFIER_READONLY); $param = $visibility - ? ($function->addPromotedParameter($item->var->name))->setVisibility($visibility) + ? ($function->addPromotedParameter($item->var->name))->setVisibility($visibility)->setReadonly($isReadonly) : $function->addParameter($item->var->name); $param->setType($item->type ? $this->toPhp($item->type) : null); $param->setReference($item->byRef); diff --git a/tests/PhpGenerator/expected/Extractor.classes.81.expect b/tests/PhpGenerator/expected/Extractor.classes.81.expect index 427d927b..831e8e31 100644 --- a/tests/PhpGenerator/expected/Extractor.classes.81.expect +++ b/tests/PhpGenerator/expected/Extractor.classes.81.expect @@ -27,3 +27,14 @@ class Class11 class Attr { } + +class Class12 +{ + private readonly string $bar; + + + public function __construct(private readonly string $foo) + { + $this->bar = "foobar"; + } +} diff --git a/tests/PhpGenerator/fixtures/classes.81.php b/tests/PhpGenerator/fixtures/classes.81.php index 3eeb9208..f283a3f7 100644 --- a/tests/PhpGenerator/fixtures/classes.81.php +++ b/tests/PhpGenerator/fixtures/classes.81.php @@ -27,3 +27,14 @@ public function bar($c = new \stdClass) class Attr { } + +class Class12 +{ + private readonly string $bar; + + + public function __construct(private readonly string $foo) + { + $this->bar = "foobar"; + } +}