Skip to content

Improve final/abstract methods in interfaces error messages #7722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ PHP NEWS
. Fixed bug #81684 (Using null coalesce assignment with $GLOBALS["x"] produces
opcode error). (ilutov)
. Fixed bug #81656 (GCC-11 silently ignores -R). (Michael Wallner)
. Fixed bug #81683 (Misleading "access type ... must be public" error message
on final or abstract interface methods). (ilutov)

- MBString:
. Fixed bug #81693 (mb_check_encoding(7bit) segfaults). (cmb)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug71871.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface test {

?>
--EXPECTF--
Fatal error: Access type for interface method test::test() must be public in %s on line %d
Fatal error: Interface method test::test() must not be final in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/bug71871_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface test {

?>
--EXPECTF--
Fatal error: Access type for interface method test::test() must be public in %s on line %d
Fatal error: Interface method test::test() must not be abstract in %s on line %d
10 changes: 9 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7039,10 +7039,18 @@ static zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string
}

if (in_interface) {
if (!(fn_flags & ZEND_ACC_PUBLIC) || (fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) {
if (!(fn_flags & ZEND_ACC_PUBLIC)) {
zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
"%s::%s() must be public", ZSTR_VAL(ce->name), ZSTR_VAL(name));
}
if (fn_flags & ZEND_ACC_FINAL) {
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
"%s::%s() must not be final", ZSTR_VAL(ce->name), ZSTR_VAL(name));
}
if (fn_flags & ZEND_ACC_ABSTRACT) {
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
"%s::%s() must not be abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
}
op_array->fn_flags |= ZEND_ACC_ABSTRACT;
}

Expand Down