diff --git a/src/Entity/PropertyDef.php b/src/Entity/PropertyDef.php index 50038455..01144c50 100644 --- a/src/Entity/PropertyDef.php +++ b/src/Entity/PropertyDef.php @@ -21,6 +21,7 @@ class PropertyDef public string $class = ''; public array $typeCheck = []; public string $typeStr = ''; + public bool $promoted = false; public function __construct(string $name, int $flags, string $type, ?string $default = null, bool $nullable = false) { diff --git a/src/Preprocessor.php b/src/Preprocessor.php index 0fc254cb..0f7e0f27 100644 --- a/src/Preprocessor.php +++ b/src/Preprocessor.php @@ -324,7 +324,7 @@ class Preprocessor extends CompilerBase // Promoted property defaults belong to the constructor parameter, // not to the property default table. The property itself must stay // uninitialized until __construct assigns it. - $this->addClassProperty($phpName, $param->flags, $param->type, null, $nullable, $param); + $this->addClassProperty($phpName, $param->flags, $param->type, null, $nullable, $param, true); } if ($param->variadic) { if ($i !== $last) { @@ -676,7 +676,7 @@ class Preprocessor extends CompilerBase * Create and register a class property with type normalization, shared by * regular property declarations and constructor property promotion. */ - protected function addClassProperty(string $name, int $flags, ?NodeAbstract $typeNode, $defaultNode, bool $nullable, NodeAbstract $errorNode): PropertyDef + protected function addClassProperty(string $name, int $flags, ?NodeAbstract $typeNode, $defaultNode, bool $nullable, NodeAbstract $errorNode, bool $promoted = false): PropertyDef { $flags = $this->parseModifiers($flags); $class = ''; @@ -701,6 +701,7 @@ class Preprocessor extends CompilerBase $propDef = new PropertyDef($name, $flags, $type, $default, $nullable); $propDef->class = $class; $propDef->arrayInitPlan = $arrayInitPlan; + $propDef->promoted = $promoted; if ($typeNode instanceof NullableType || $typeNode instanceof UnionType || $typeNode instanceof IntersectionType) { $typeInfo = $this->buildTypeCheckFromNode($typeNode); $propDef->typeCheck = $typeInfo['check']; diff --git a/src/gen_stub.php b/src/gen_stub.php index 733eb245..fab12470 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -3202,6 +3202,7 @@ class PropertyInfo extends VariableLike private /* readonly */ ?string $defaultValueString; private /* readonly */ bool $isDocReadonly; private /* readonly */ bool $isVirtual; + private /* readonly */ bool $isPromoted; /** * @param AttributeInfo[] $attributes @@ -3216,6 +3217,7 @@ class PropertyInfo extends VariableLike ?string $defaultValueString, bool $isDocReadonly, bool $isVirtual, + bool $isPromoted, ?string $link, ?int $phpVersionIdMinimumCompatibility, array $attributes, @@ -3227,6 +3229,7 @@ class PropertyInfo extends VariableLike $this->defaultValueString = $defaultValueString; $this->isDocReadonly = $isDocReadonly; $this->isVirtual = $isVirtual; + $this->isPromoted = $isPromoted; parent::__construct($flags, $type, $phpDocType, $link, $phpVersionIdMinimumCompatibility, $attributes, $exposedDocComment); } @@ -3364,6 +3367,10 @@ class PropertyInfo extends VariableLike $flags->addForVersionsAbove("ZEND_ACC_VIRTUAL", PHP_84_VERSION_ID); } + if ($this->isPromoted) { + $flags->addForVersionsAbove("ZEND_ACC_PROMOTED", PHP_80_VERSION_ID); + } + return $flags; } @@ -4972,7 +4979,8 @@ function parseFunctionLike( $property->getComments(), $prettyPrinter, $minimumPhpVersionIdCompatibility, - AttributeInfo::createFromGroups($property->attrGroups) + AttributeInfo::createFromGroups($property->attrGroups), + true ); } @@ -5186,7 +5194,8 @@ function parseProperty( array $comments, PrettyPrinterAbstract $prettyPrinter, ?int $phpVersionIdMinimumCompatibility, - array $attributes + array $attributes, + bool $isPromoted = false ): PropertyInfo { $phpDocType = null; @@ -5228,6 +5237,7 @@ function parseProperty( $property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null, $isDocReadonly, $isVirtual, + $isPromoted, $link, $phpVersionIdMinimumCompatibility, $attributes, diff --git a/tests/aot/symfony/sensitive-promoted-readonly.phpt b/tests/aot/symfony/sensitive-promoted-readonly.phpt index 9be68e80..d8407b2c 100644 --- a/tests/aot/symfony/sensitive-promoted-readonly.phpt +++ b/tests/aot/symfony/sensitive-promoted-readonly.phpt @@ -1,7 +1,5 @@ --TEST-- Symfony pattern: SensitiveParameter attribute on promoted readonly constructor parameter ---XFAIL-- -Known AOT bug: ReflectionProperty::isPromoted() is false for promoted constructor properties. --FILE--