@@ -1952,10 +1952,6 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
19521952 zend_function * new_fn ;
19531953 bool check_inheritance = false;
19541954
1955- if ((fn -> common .fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) == (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) {
1956- zend_error (E_COMPILE_WARNING , "Private methods cannot be final as they are never overridden by other classes" );
1957- }
1958-
19591955 if ((existing_fn = zend_hash_find_ptr (& ce -> function_table , key )) != NULL ) {
19601956 /* if it is the same function with the same visibility and has not been assigned a class scope yet, regardless
19611957 * of where it is coming from there is no conflict and we do not need to add it again */
@@ -2036,6 +2032,17 @@ static void zend_fixup_trait_method(zend_function *fn, zend_class_entry *ce) /*
20362032}
20372033/* }}} */
20382034
2035+ static void zend_traits_check_private_final_inheritance (uint32_t original_fn_flags , zend_function * fn_copy , zend_string * name )
2036+ {
2037+ /* If the function was originally already private+final, then it will have already been warned about.
2038+ * If the function became private+final only after applying modifiers, we need to emit the same warning. */
2039+ if ((original_fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) != (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )
2040+ && (fn_copy -> common .fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) == (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )
2041+ && !zend_string_equals_literal_ci (name , ZEND_CONSTRUCTOR_FUNC_NAME )) {
2042+ zend_error (E_COMPILE_WARNING , "Private methods cannot be final as they are never overridden by other classes" );
2043+ }
2044+ }
2045+
20392046static void zend_traits_copy_functions (zend_string * fnname , zend_function * fn , zend_class_entry * ce , HashTable * exclude_table , zend_class_entry * * aliases ) /* {{{ */
20402047{
20412048 zend_trait_alias * alias , * * alias_ptr ;
@@ -2061,6 +2068,8 @@ static void zend_traits_copy_functions(zend_string *fnname, zend_function *fn, z
20612068 fn_copy .common .fn_flags = alias -> modifiers | fn -> common .fn_flags ;
20622069 }
20632070
2071+ zend_traits_check_private_final_inheritance (fn -> common .fn_flags , & fn_copy , alias -> alias );
2072+
20642073 lcname = zend_string_tolower (alias -> alias );
20652074 zend_add_trait_method (ce , alias -> alias , lcname , & fn_copy );
20662075 zend_string_release_ex (lcname , 0 );
@@ -2098,6 +2107,8 @@ static void zend_traits_copy_functions(zend_string *fnname, zend_function *fn, z
20982107 }
20992108 }
21002109
2110+ zend_traits_check_private_final_inheritance (fn -> common .fn_flags , & fn_copy , fnname );
2111+
21012112 zend_add_trait_method (ce , fn -> common .function_name , fnname , & fn_copy );
21022113 }
21032114}
0 commit comments