Skip to content

Commit f151934

Browse files
committed
Improve final/abstract methods in interfaces error messages
Closes #81683
1 parent 15e7e57 commit f151934

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Zend/tests/bug81683_1.phpt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #81683: Misleading "access type ... must be public" error message on final interface methods
3+
--FILE--
4+
<?php
5+
interface Foo {
6+
public final function bar();
7+
}
8+
?>
9+
--EXPECTF--
10+
Fatal error: Interface method Foo::bar() must not be final in %s on line %d

Zend/tests/bug81683_2.phpt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #81683: Misleading "access type ... must be public" error message on abstract interface methods
3+
--FILE--
4+
<?php
5+
interface Foo {
6+
public abstract function bar();
7+
}
8+
?>
9+
--EXPECTF--
10+
Fatal error: Interface method Foo::bar() must not be abstract in %s on line %d

Zend/zend_compile.c

+9-1
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)