diff --git a/src/PhpGenerator/Factory.php b/src/PhpGenerator/Factory.php index 9509e763..b2854073 100644 --- a/src/PhpGenerator/Factory.php +++ b/src/PhpGenerator/Factory.php @@ -200,7 +200,7 @@ public function fromCallable(callable $from): Method|GlobalFunction|Closure public function fromParameterReflection(\ReflectionParameter $from): Parameter { $param = $from->isPromoted() - ? new PromotedParameter($from->name) + ? (new PromotedParameter($from->name))->setReadOnly(PHP_VERSION_ID >= 80100 ? $from->getDeclaringClass()->getProperty($from->name)->isReadonly() : false) : new Parameter($from->name); $param->setReference($from->isPassedByReference()); $param->setType((string) $from->getType()); diff --git a/tests/PhpGenerator/ClassType.from.81.phpt b/tests/PhpGenerator/ClassType.from.81.phpt index 6dd3db33..ce30dfc1 100644 --- a/tests/PhpGenerator/ClassType.from.81.phpt +++ b/tests/PhpGenerator/ClassType.from.81.phpt @@ -12,5 +12,7 @@ require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/fixtures/classes.81.php'; $res[] = ClassType::from(new Abc\Class11); +$res[] = ClassType::from(Abc\Attr::class); +$res[] = ClassType::from(Abc\Class12::class); sameFile(__DIR__ . '/expected/ClassType.from.81.expect', implode("\n", $res)); diff --git a/tests/PhpGenerator/expected/ClassType.from.81.expect b/tests/PhpGenerator/expected/ClassType.from.81.expect index f52acd06..22b0d789 100644 --- a/tests/PhpGenerator/expected/ClassType.from.81.expect +++ b/tests/PhpGenerator/expected/ClassType.from.81.expect @@ -16,3 +16,19 @@ class Class11 { } } + +#[\Attribute] +class Attr +{ +} + +class Class12 +{ + private readonly string $bar; + + + public function __construct( + public readonly string $foo, + ) { + } +}