Skip to content

Commit 02cb104

Browse files
committed
Fix name collisions when an attribute is repeatable
1 parent 61d2b7a commit 02cb104

File tree

7 files changed

+108
-83
lines changed

7 files changed

+108
-83
lines changed

Zend/zend_attributes_arginfo.h

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Zend/zend_builtin_functions_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/gen_stub.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,8 +2567,12 @@ function (Name $item) {
25672567
$code .= "\n#if (PHP_VERSION_ID >= " . PHP_82_VERSION_ID . ")";
25682568
}
25692569

2570-
foreach ($this->attributes as $attribute) {
2571-
$code .= $attribute->generateCode("zend_add_class_attribute(class_entry", "class_$escapedName", $allConstInfos);
2570+
foreach ($this->attributes as $key => $attribute) {
2571+
$code .= $attribute->generateCode(
2572+
"zend_add_class_attribute(class_entry",
2573+
"class_{$escapedName}_" . ($key + 1),
2574+
$allConstInfos
2575+
);
25722576
}
25732577

25742578
if (!$php82MinimumCompatibility) {
@@ -4134,13 +4138,21 @@ static function (FuncInfo $funcInfo) use ($allConstInfos) {
41344138
$functionTable = "CG(function_table)";
41354139
}
41364140

4137-
foreach ($funcInfo->attributes as $attribute) {
4138-
$code .= $attribute->generateCode("zend_add_function_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", sizeof(\"" . $funcInfo->name->getNameForAttributes() . "\") - 1)", "func_" . $funcInfo->name->getNameForAttributes(), $allConstInfos);
4141+
foreach ($funcInfo->attributes as $key => $attribute) {
4142+
$code .= $attribute->generateCode(
4143+
"zend_add_function_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", sizeof(\"" . $funcInfo->name->getNameForAttributes() . "\") - 1)",
4144+
"func_" . $funcInfo->name->getNameForAttributes() . "_" . ($key + 1),
4145+
$allConstInfos
4146+
);
41394147
}
41404148

41414149
foreach ($funcInfo->args as $index => $arg) {
4142-
foreach ($arg->attributes as $attribute) {
4143-
$code .= $attribute->generateCode("zend_add_parameter_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", sizeof(\"" . $funcInfo->name->getNameForAttributes() . "\") - 1), $index", "func_{$funcInfo->name->getNameForAttributes()}_arg{$index}", $allConstInfos);
4150+
foreach ($arg->attributes as $key => $attribute) {
4151+
$code .= $attribute->generateCode(
4152+
"zend_add_parameter_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", sizeof(\"" . $funcInfo->name->getNameForAttributes() . "\") - 1), $index",
4153+
"func_{$funcInfo->name->getNameForAttributes()}_arg{$index}_" . ($key + 1),
4154+
$allConstInfos
4155+
);
41444156
}
41454157
}
41464158

@@ -4160,8 +4172,12 @@ function generateConstantAttributeInitialization(iterable $constInfos, iterable
41604172
static function (ConstInfo $constInfo) use ($allConstInfos) {
41614173
$code = null;
41624174

4163-
foreach ($constInfo->attributes as $attribute) {
4164-
$code .= $attribute->generateCode("zend_add_class_constant_attribute(class_entry, const_" . $constInfo->name->getDeclarationName(), "const_" . $constInfo->name->getDeclarationName(), $allConstInfos);
4175+
foreach ($constInfo->attributes as $key => $attribute) {
4176+
$code .= $attribute->generateCode(
4177+
"zend_add_class_constant_attribute(class_entry, const_" . $constInfo->name->getDeclarationName(),
4178+
"const_" . $constInfo->name->getDeclarationName() . "_" . ($key + 1),
4179+
$allConstInfos
4180+
);
41654181
}
41664182

41674183
return $code;
@@ -4176,8 +4192,12 @@ static function (ConstInfo $constInfo) use ($allConstInfos) {
41764192
function generatePropertyAttributeInitialization(iterable $propertyInfos, iterable $allConstInfos): string {
41774193
$code = "";
41784194
foreach ($propertyInfos as $propertyInfo) {
4179-
foreach ($propertyInfo->attributes as $attribute) {
4180-
$code .= $attribute->generateCode("zend_add_property_attribute(class_entry, property_" . $propertyInfo->name->getDeclarationName(), "property_" . $propertyInfo->name->getDeclarationName(), $allConstInfos);
4195+
foreach ($propertyInfo->attributes as $key => $attribute) {
4196+
$code .= $attribute->generateCode(
4197+
"zend_add_property_attribute(class_entry, property_" . $propertyInfo->name->getDeclarationName(),
4198+
"property_" . $propertyInfo->name->getDeclarationName() . "_" . ($key + 1),
4199+
$allConstInfos
4200+
);
41814201
}
41824202
}
41834203

ext/oci8/oci8_arginfo.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/basic_functions_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/test.stub.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function returnsThrowable(): Exception {}
5050
trait _ZendTestTrait {
5151
/** @var int */
5252
#[ZendTestAttribute]
53+
#[ZendTestAttribute]
5354
public const TEST_CONST = 1;
5455

5556
/** @var mixed */
@@ -61,7 +62,7 @@ trait _ZendTestTrait {
6162
public function testMethod(): bool {}
6263
}
6364

64-
#[Attribute(Attribute::TARGET_ALL)]
65+
#[Attribute(Attribute::TARGET_ALL|Attribute::IS_REPEATABLE)]
6566
final class ZendTestAttribute {
6667

6768
}

0 commit comments

Comments
 (0)