Skip to content

Commit 756a083

Browse files
committed
Go back to unique attribute names
1 parent cd4d759 commit 756a083

File tree

5 files changed

+17
-35
lines changed

5 files changed

+17
-35
lines changed

Zend/tests/attributes_003.phpt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ Resolve attribute names
55
function dump_attributes($attributes) {
66
$arr = [];
77
foreach ($attributes as $attribute) {
8-
if (!isset($arr[$attribute->getName()])) {
9-
$arr[$attribute->getName()] = [];
10-
}
11-
$arr[$attribute->getName()][] = $attribute->getArguments();
8+
$arr[$attribute->getName()] = $attribute->getArguments();
129
}
1310
var_dump($arr);
1411
}
@@ -35,11 +32,8 @@ array(1) {
3532
array(1) {
3633
[0]=>
3734
array(1) {
38-
[0]=>
39-
array(1) {
40-
["foo"]=>
41-
string(3) "bar"
42-
}
35+
["foo"]=>
36+
string(3) "bar"
4337
}
4438
}
4539
}

Zend/zend_ast.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,10 +2137,9 @@ ZEND_API void zend_ast_convert_to_object(zval *p, zend_ast *ast, zend_class_entr
21372137
}
21382138
}
21392139

2140-
ZEND_API zval *zend_ast_convert_attributes(HashTable *attributes, zend_class_entry *ce)
2140+
zval *zend_ast_convert_attributes(HashTable *attributes, zend_class_entry *ce)
21412141
{
21422142
zval *val, tmp;
2143-
HashTable *ht, *ht2;
21442143
zval *res = emalloc(sizeof(zval));
21452144

21462145
array_init(res);
@@ -2185,16 +2184,10 @@ void zend_ast_add_attribute(zend_ast *name, zend_ast *value) /* {{{ */
21852184
if (value->kind == ZEND_AST_ZVAL) {
21862185
zval *zv = zend_ast_get_zval(value);
21872186

2188-
if (Z_TYPE_P(zv) == IS_ARRAY) {
2189-
ZVAL_COPY_VALUE(val, zv);
2190-
} else {
2191-
array_init(val);
2192-
zend_hash_next_index_insert_new(Z_ARRVAL_P(val), zv);
2193-
}
2187+
ZVAL_COPY_VALUE(val, zv);
21942188
} else {
21952189
zend_const_expr_to_zval(&tmp, value);
2196-
array_init(val);
2197-
zend_hash_next_index_insert_new(Z_ARRVAL_P(val), &tmp);
2190+
ZVAL_COPY_VALUE(val, &tmp);
21982191
}
21992192
} else {
22002193
array_init(val);

Zend/zend_ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,5 +356,5 @@ static zend_always_inline zend_ast *zend_ast_list_rtrim(zend_ast *ast) {
356356

357357
void zend_ast_add_attribute(zend_ast *name, zend_ast *value);
358358
zend_ast *zend_ast_add_attribute_value(zend_ast *list_ast, zend_ast *val_ast);
359-
ZEND_API zval *zend_ast_convert_attributes(HashTable *attributes, zend_class_entry *ce);
359+
zval *zend_ast_convert_attributes(HashTable *attributes, zend_class_entry *ce);
360360
#endif

Zend/zend_language_parser.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
234234
%type <ast> group_use_declaration inline_use_declarations inline_use_declaration
235235
%type <ast> mixed_group_use_declaration use_declaration unprefixed_use_declaration
236236
%type <ast> unprefixed_use_declarations const_decl inner_statement
237-
%type <ast> attribute_values expr optional_expr while_statement for_statement foreach_variable
237+
%type <ast> attribute_arguments expr optional_expr while_statement for_statement foreach_variable
238238
%type <ast> foreach_statement declare_statement finally_statement unset_variable variable
239239
%type <ast> extends_from parameter optional_type_without_static argument global_var
240240
%type <ast> static_var class_statement annotated_class_statement trait_adaptation trait_precedence trait_alias
@@ -314,14 +314,14 @@ name:
314314
| T_NS_SEPARATOR namespace_name { $$ = $2; $$->attr = ZEND_NAME_FQ; }
315315
;
316316

317-
attribute_values:
317+
attribute_arguments:
318318
expr { $$ = $1; }
319-
| attribute_values ',' expr { $$ = zend_ast_add_attribute_value($1, $3); }
319+
| attribute_arguments ',' expr { $$ = zend_ast_add_attribute_value($1, $3); }
320320
;
321321

322322
attribute_decl:
323323
class_name_reference { zend_ast_add_attribute($1, NULL); }
324-
| class_name_reference '(' attribute_values ')' { zend_ast_add_attribute($1, $3); }
324+
| class_name_reference '(' attribute_arguments ')' { zend_ast_add_attribute($1, $3); }
325325
;
326326

327327
attribute:

ext/reflection/php_reflection.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,24 +1057,19 @@ static void reflection_attribute_factory(zval *object, zend_string *name, zval *
10571057
/* }}} */
10581058

10591059

1060-
static zval* convert_attributes(zval *ret, HashTable *attributes, zend_class_entry *ce)
1060+
static void convert_attributes(zval *ret, HashTable *attributes, zend_class_entry *ce)
10611061
{
10621062
zend_string *attribute_name;
1063-
zval *attrs, *attr, *object;
1063+
zval *attr, *object;
10641064
zval *converted_attributes;
10651065

10661066
array_init(ret);
10671067

1068-
ZEND_HASH_FOREACH_STR_KEY_VAL(attributes, attribute_name, attrs) {
1068+
ZEND_HASH_FOREACH_STR_KEY_VAL(attributes, attribute_name, attr) {
10691069
if (attribute_name) {
1070-
1071-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(attrs), attr) {
1072-
converted_attributes = zend_ast_convert_attributes(Z_ARRVAL_P(attr), ce);
1073-
1074-
reflection_attribute_factory(object, attribute_name, converted_attributes);
1075-
1076-
zend_hash_next_index_insert(Z_ARRVAL_P(ret), object);
1077-
} ZEND_HASH_FOREACH_END();
1070+
converted_attributes = zend_ast_convert_attributes(Z_ARRVAL_P(attr), ce);
1071+
reflection_attribute_factory(object, attribute_name, converted_attributes);
1072+
zend_hash_next_index_insert(Z_ARRVAL_P(ret), object);
10781073
}
10791074
} ZEND_HASH_FOREACH_END();
10801075
}

0 commit comments

Comments
 (0)