Skip to content

Commit e104840

Browse files
committed
Support the #[\AllowDynamicProperties] attribute in stubs
1 parent 20a9027 commit e104840

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

build/gen_stub.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,8 @@ class ClassInfo {
22642264
/** @var bool */
22652265
public $isStrictProperties;
22662266
/** @var bool */
2267+
public $allowsDynamicProperties;
2268+
/** @var bool */
22672269
public $isNotSerializable;
22682270
/** @var Name[] */
22692271
public $extends;
@@ -2296,6 +2298,7 @@ public function __construct(
22962298
?SimpleType $enumBackingType,
22972299
bool $isDeprecated,
22982300
bool $isStrictProperties,
2301+
bool $allowsDynamicProperties,
22992302
bool $isNotSerializable,
23002303
array $extends,
23012304
array $implements,
@@ -2312,6 +2315,7 @@ public function __construct(
23122315
$this->enumBackingType = $enumBackingType;
23132316
$this->isDeprecated = $isDeprecated;
23142317
$this->isStrictProperties = $isStrictProperties;
2318+
$this->allowsDynamicProperties = $allowsDynamicProperties;
23152319
$this->isNotSerializable = $isNotSerializable;
23162320
$this->extends = $extends;
23172321
$this->implements = $implements;
@@ -2400,6 +2404,10 @@ function (Name $item) {
24002404
$code .= $property->getDeclaration($allConstInfos);
24012405
}
24022406

2407+
if ($this->allowsDynamicProperties) {
2408+
$code .= "\tzend_add_class_attribute(class_entry, zend_ce_allow_dynamic_properties->name, 0);\n";
2409+
}
2410+
24032411
if ($attributeInitializationCode = generateAttributeInitialization($this->funcInfos, $this->cond)) {
24042412
$code .= "\n" . $attributeInitializationCode;
24052413
}
@@ -2443,6 +2451,10 @@ private function getFlagsAsString(): string
24432451
$flags[] = "ZEND_ACC_NO_DYNAMIC_PROPERTIES";
24442452
}
24452453

2454+
if ($this->allowsDynamicProperties) {
2455+
$flags[] = "ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES";
2456+
}
2457+
24462458
if ($this->isNotSerializable) {
24472459
$flags[] = "ZEND_ACC_NOT_SERIALIZABLE";
24482460
}
@@ -3264,6 +3276,7 @@ function parseClass(
32643276
$isDeprecated = false;
32653277
$isStrictProperties = false;
32663278
$isNotSerializable = false;
3279+
$allowsDynamicProperties = false;
32673280

32683281
if ($comment) {
32693282
$tags = parseDocComment($comment);
@@ -3280,6 +3293,18 @@ function parseClass(
32803293
}
32813294
}
32823295

3296+
foreach ($class->attrGroups as $attrGroup) {
3297+
foreach ($attrGroup->attrs as $attr) {
3298+
switch ($attr->name->toCodeString()) {
3299+
case '\\AllowDynamicProperties':
3300+
$allowsDynamicProperties = true;
3301+
break;
3302+
default:
3303+
throw new Exception("Unhandled attribute {$attr->name->toCodeString()}.");
3304+
}
3305+
}
3306+
}
3307+
32833308
$extends = [];
32843309
$implements = [];
32853310

@@ -3310,6 +3335,7 @@ function parseClass(
33103335
? SimpleType::fromNode($class->scalarType) : null,
33113336
$isDeprecated,
33123337
$isStrictProperties,
3338+
$allowsDynamicProperties,
33133339
$isNotSerializable,
33143340
$extends,
33153341
$implements,

0 commit comments

Comments
 (0)