Skip to content

Commit b991ce9

Browse files
committed
Improve final/abstract methods in interfaces error messages
Closes #81683 Closes GH-7722
1 parent 53ae2b1 commit b991ce9

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
. Fixed bug #81684 (Using null coalesce assignment with $GLOBALS["x"] produces
88
opcode error). (ilutov)
99
. Fixed bug #81656 (GCC-11 silently ignores -R). (Michael Wallner)
10+
. Fixed bug #81683 (Misleading "access type ... must be public" error message
11+
on final or abstract interface methods). (ilutov)
1012

1113
- MBString:
1214
. Fixed bug #81693 (mb_check_encoding(7bit) segfaults). (cmb)

Zend/tests/bug71871.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ interface test {
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Access type for interface method test::test() must be public in %s on line %d
12+
Fatal error: Interface method test::test() must not be final in %s on line %d

Zend/tests/bug71871_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ interface test {
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Access type for interface method test::test() must be public in %s on line %d
12+
Fatal error: Interface method test::test() must not be abstract in %s on line %d

Zend/zend_compile.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7039,10 +7039,18 @@ static zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string
70397039
}
70407040

70417041
if (in_interface) {
7042-
if (!(fn_flags & ZEND_ACC_PUBLIC) || (fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) {
7042+
if (!(fn_flags & ZEND_ACC_PUBLIC)) {
70437043
zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
70447044
"%s::%s() must be public", ZSTR_VAL(ce->name), ZSTR_VAL(name));
70457045
}
7046+
if (fn_flags & ZEND_ACC_FINAL) {
7047+
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
7048+
"%s::%s() must not be final", ZSTR_VAL(ce->name), ZSTR_VAL(name));
7049+
}
7050+
if (fn_flags & ZEND_ACC_ABSTRACT) {
7051+
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
7052+
"%s::%s() must not be abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
7053+
}
70467054
op_array->fn_flags |= ZEND_ACC_ABSTRACT;
70477055
}
70487056

0 commit comments

Comments
 (0)