diff --git a/Zend/tests/attributes/001_placement.phpt b/Zend/tests/attributes/001_placement.phpt index 02e6c27aa415c..8f16f4cbe8481 100644 --- a/Zend/tests/attributes/001_placement.phpt +++ b/Zend/tests/attributes/001_placement.phpt @@ -44,81 +44,96 @@ $sources = [ foreach ($sources as $r) { $attr = $r->getAttributes(); - var_dump(count($attr)); + var_dump(get_class($r), count($attr)); foreach ($attr as $a) { var_dump($a->getName(), $a->getArguments()); } + + echo "\n"; } ?> --EXPECT-- +string(15) "ReflectionClass" int(1) string(2) "A1" array(1) { [0]=> int(1) } + +string(23) "ReflectionClassConstant" int(1) string(2) "A1" array(1) { [0]=> int(2) } -int(1) -string(2) "A1" -array(1) { - [0]=> - int(2) -} -int(1) -string(2) "A1" -array(1) { - [0]=> - int(3) -} + +string(23) "ReflectionClassConstant" +int(0) + +string(18) "ReflectionProperty" int(1) string(2) "A1" array(1) { [0]=> int(3) } + +string(18) "ReflectionProperty" +int(0) + +string(16) "ReflectionMethod" int(1) string(2) "A1" array(1) { [0]=> int(4) } + +string(19) "ReflectionParameter" int(1) string(2) "A1" array(1) { [0]=> int(5) } + +string(19) "ReflectionParameter" int(1) string(2) "A1" array(1) { [0]=> int(6) } + +string(16) "ReflectionObject" int(1) string(2) "A1" array(1) { [0]=> int(7) } + +string(18) "ReflectionFunction" int(1) string(2) "A1" array(1) { [0]=> int(8) } + +string(18) "ReflectionFunction" int(1) string(2) "A1" array(1) { [0]=> int(9) } + +string(18) "ReflectionFunction" int(1) string(2) "A1" array(1) { diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 7bd732ea68088..2cb11a4e6b22a 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1591,7 +1591,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio smart_str_appends(str, "const "); goto simple_list; case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES: - zend_ast_export_attributes(str, ast->child[1], indent, 1); + if (ast->child[1]) { + zend_ast_export_attributes(str, ast->child[1], indent, 1); + } zend_ast_export_ex(str, ast->child[0], 0, indent); break; case ZEND_AST_NAME_LIST: @@ -2190,9 +2192,8 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr) case ZEND_AST_PARAM: ast->child[3] = attr; break; - case ZEND_AST_CLASS_CONST_DECL: - ast = zend_ast_create(ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES, ast, attr); - ast->lineno = ast->child[0]->lineno; + case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES: + ast->child[1] = attr; break; EMPTY_SWITCH_DEFAULT_CASE() } diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 1501df9f929a1..e51cfcbc0cdc5 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2381,7 +2381,7 @@ static inline zend_bool zend_is_variable_or_call(zend_ast *ast) /* {{{ */ static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */ { return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL - || ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL + || ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES || ast->kind == ZEND_AST_USE_TRAIT || ast->kind == ZEND_AST_METHOD; } /* }}} */ @@ -6517,11 +6517,9 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t flags, H ZVAL_UNDEF(&value_zv); } - if (attributes) { - GC_ADDREF(attributes); - } - zend_declare_typed_property(ce, name, &value_zv, flags, doc_comment, attributes, type); + + attributes = NULL; } } /* }}} */ @@ -6539,10 +6537,6 @@ void zend_compile_prop_group(zend_ast *list) /* {{{ */ } zend_compile_prop_decl(prop_ast, type_ast, list->attr, attributes); - - if (attributes) { - zend_array_release(attributes); - } } /* }}} */ @@ -6588,16 +6582,10 @@ void zend_compile_class_const_decl(zend_ast *ast, zend_ast *attr_ast) /* {{{ */ zend_check_const_and_trait_alias_attr(ast->attr, "constant"); } - if (attributes) { - GC_ADDREF(attributes); - } - zend_const_expr_to_zval(&value_zv, value_ast); zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment, attributes); - } - if (attributes) { - zend_array_release(attributes); + attributes = NULL; } } /* }}} */ @@ -8909,9 +8897,6 @@ void zend_compile_stmt(zend_ast *ast) /* {{{ */ case ZEND_AST_PROP_GROUP: zend_compile_prop_group(ast); break; - case ZEND_AST_CLASS_CONST_DECL: - zend_compile_class_const_decl(ast, NULL); - break; case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES: zend_compile_class_const_decl(ast->child[0], ast->child[1]); break; diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index b64f807615c13..3740b6faedb09 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -786,7 +786,7 @@ annotated_class_statement: { $$ = zend_ast_create(ZEND_AST_PROP_GROUP, $2, $3, NULL); $$->attr = $1; } | method_modifiers T_CONST class_const_list ';' - { $$ = $3; $$->attr = $1; } + { $$ = zend_ast_create(ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES, $3, NULL); $3->attr = $1; } | method_modifiers function returns_ref identifier backup_doc_comment '(' parameter_list ')' return_type backup_fn_flags method_body backup_fn_flags { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,