Skip to content

Commit 051b396

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Improve final/abstract methods in interfaces error messages
2 parents 335b940 + b991ce9 commit 051b396

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

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
@@ -6976,10 +6976,18 @@ static zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string
69766976
}
69776977

69786978
if (in_interface) {
6979-
if (!(fn_flags & ZEND_ACC_PUBLIC) || (fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) {
6979+
if (!(fn_flags & ZEND_ACC_PUBLIC)) {
69806980
zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
69816981
"%s::%s() must be public", ZSTR_VAL(ce->name), ZSTR_VAL(name));
69826982
}
6983+
if (fn_flags & ZEND_ACC_FINAL) {
6984+
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
6985+
"%s::%s() must not be final", ZSTR_VAL(ce->name), ZSTR_VAL(name));
6986+
}
6987+
if (fn_flags & ZEND_ACC_ABSTRACT) {
6988+
zend_error_noreturn(E_COMPILE_ERROR, "Interface method "
6989+
"%s::%s() must not be abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
6990+
}
69836991
op_array->fn_flags |= ZEND_ACC_ABSTRACT;
69846992
}
69856993

0 commit comments

Comments
 (0)