Skip to content

Commit 33d926d

Browse files
committed
Improve final/abstract methods in interfaces error messages
Closes #81683 Closes GH-7722
1 parent 15e7e57 commit 33d926d

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
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed bug #81216 (Nullsafe operator leaks dynamic property name). (Dmitry)
77
. Fixed bug #81684 (Using null coalesce assignment with $GLOBALS["x"] produces
88
opcode error). (ilutov)
9+
. Fixed bug #81683 (Misleading "access type ... must be public" error message
10+
on final or abstract interface methods). (ilutov)
911

1012
- MBString:
1113
. 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)