@@ -6216,6 +6216,42 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
6216
6216
}
6217
6217
/* }}} */
6218
6218
6219
+ static HashTable * zend_compile_resolve_attributes (HashTable * declared_attributes )
6220
+ {
6221
+ zval * attr , * attrname , * val , tmp ;
6222
+ zend_string * resolved_name ;
6223
+ zend_string * key ;
6224
+ // declared attributes are in structure: idx => ["class" => "...", 0 => arg1, 1 => arg2, ...]
6225
+ // resolved attributes are in structure fqcn => [ [0 => arg1, 1 => arg2], [0 => arg12, 1 => arg22] ]
6226
+ HashTable * resolved_attributes ;
6227
+
6228
+ ALLOC_HASHTABLE (resolved_attributes );
6229
+ zend_hash_init (resolved_attributes , 8 , NULL , ZVAL_PTR_DTOR , 0 );
6230
+
6231
+ ZEND_HASH_FOREACH_STR_KEY_VAL (declared_attributes , key , attr ) {
6232
+ // @todo not yet "class" key with ast that stores ZEND_NAME_*,
6233
+ // first step here is to have class name as key of attributes and always assume relative to imports
6234
+ resolved_name = zend_resolve_class_name (key , ZEND_NAME_NOT_FQ );
6235
+
6236
+ ZVAL_NULL (& tmp );
6237
+ val = zend_hash_add (resolved_attributes , resolved_name , & tmp );
6238
+
6239
+ if (val ) {
6240
+ array_init (val );
6241
+ } else {
6242
+ val = zend_hash_find (resolved_attributes , resolved_name );
6243
+ }
6244
+
6245
+ zend_hash_next_index_insert (Z_ARRVAL_P (val ), attr );
6246
+ Z_TRY_ADDREF_P (attr );
6247
+
6248
+ } ZEND_HASH_FOREACH_END ();
6249
+
6250
+ zend_hash_destroy (declared_attributes );
6251
+
6252
+ return resolved_attributes ;
6253
+ }
6254
+
6219
6255
void zend_compile_func_decl (znode * result , zend_ast * ast , zend_bool toplevel ) /* {{{ */
6220
6256
{
6221
6257
zend_ast_decl * decl = (zend_ast_decl * ) ast ;
@@ -6251,7 +6287,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
6251
6287
op_array -> doc_comment = zend_string_copy (decl -> doc_comment );
6252
6288
}
6253
6289
if (decl -> attributes ) {
6254
- op_array -> attributes = decl -> attributes ;
6290
+ op_array -> attributes = zend_compile_resolve_attributes ( decl -> attributes ) ;
6255
6291
decl -> attributes = NULL ;
6256
6292
}
6257
6293
if (decl -> kind == ZEND_AST_CLOSURE || decl -> kind == ZEND_AST_ARROW_FUNC ) {
@@ -6680,7 +6716,7 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6680
6716
ce -> info .user .doc_comment = zend_string_copy (decl -> doc_comment );
6681
6717
}
6682
6718
if (decl -> attributes ) {
6683
- ce -> info .user .attributes = decl -> attributes ;
6719
+ ce -> info .user .attributes = zend_compile_resolve_attributes ( decl -> attributes ) ;
6684
6720
decl -> attributes = NULL ;
6685
6721
}
6686
6722
0 commit comments