@@ -1949,10 +1949,6 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
1949
1949
zend_function * new_fn ;
1950
1950
bool check_inheritance = false;
1951
1951
1952
- if ((fn -> common .fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) == (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) {
1953
- zend_error (E_COMPILE_WARNING , "Private methods cannot be final as they are never overridden by other classes" );
1954
- }
1955
-
1956
1952
if ((existing_fn = zend_hash_find_ptr (& ce -> function_table , key )) != NULL ) {
1957
1953
/* if it is the same function with the same visibility and has not been assigned a class scope yet, regardless
1958
1954
* of where it is coming from there is no conflict and we do not need to add it again */
@@ -2033,6 +2029,17 @@ static void zend_fixup_trait_method(zend_function *fn, zend_class_entry *ce) /*
2033
2029
}
2034
2030
/* }}} */
2035
2031
2032
+ static void zend_traits_check_private_final_inheritance (uint32_t original_fn_flags , zend_function * fn_copy , zend_string * name )
2033
+ {
2034
+ /* If the function was originally already private+final, then it will have already been warned about.
2035
+ * If the function became private+final only after applying modifiers, we need to emit the same warning. */
2036
+ if ((original_fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) != (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )
2037
+ && (fn_copy -> common .fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )) == (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )
2038
+ && !zend_string_equals_literal_ci (name , ZEND_CONSTRUCTOR_FUNC_NAME )) {
2039
+ zend_error (E_COMPILE_WARNING , "Private methods cannot be final as they are never overridden by other classes" );
2040
+ }
2041
+ }
2042
+
2036
2043
static void zend_traits_copy_functions (zend_string * fnname , zend_function * fn , zend_class_entry * ce , HashTable * exclude_table , zend_class_entry * * aliases ) /* {{{ */
2037
2044
{
2038
2045
zend_trait_alias * alias , * * alias_ptr ;
@@ -2058,6 +2065,8 @@ static void zend_traits_copy_functions(zend_string *fnname, zend_function *fn, z
2058
2065
fn_copy .common .fn_flags = alias -> modifiers | fn -> common .fn_flags ;
2059
2066
}
2060
2067
2068
+ zend_traits_check_private_final_inheritance (fn -> common .fn_flags , & fn_copy , alias -> alias );
2069
+
2061
2070
lcname = zend_string_tolower (alias -> alias );
2062
2071
zend_add_trait_method (ce , alias -> alias , lcname , & fn_copy );
2063
2072
zend_string_release_ex (lcname , 0 );
@@ -2095,6 +2104,8 @@ static void zend_traits_copy_functions(zend_string *fnname, zend_function *fn, z
2095
2104
}
2096
2105
}
2097
2106
2107
+ zend_traits_check_private_final_inheritance (fn -> common .fn_flags , & fn_copy , fnname );
2108
+
2098
2109
zend_add_trait_method (ce , fn -> common .function_name , fnname , & fn_copy );
2099
2110
}
2100
2111
}
0 commit comments