Skip to content

Commit a706d73

Browse files
AyeshGirgias
authored andcommitted
Improve interface non-public method error message
Currently interface methods with visibility `private` or `protected` fail with an error message: Access type for interface method A::b() must be omitted However, explicitly setting visibility `public` is allowed and often desired. This commit updates the error message to: Access type for interface method A::b() must be public
1 parent 467801d commit a706d73

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
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 omitted in %s on line %d
12+
Fatal error: Access type for interface method test::test() must be public 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 omitted in %s on line %d
12+
Fatal error: Access type for interface method test::test() must be public in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6945,7 +6945,7 @@ zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name,
69456945
if (in_interface) {
69466946
if (!(fn_flags & ZEND_ACC_PUBLIC) || (fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) {
69476947
zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
6948-
"%s::%s() must be omitted", ZSTR_VAL(ce->name), ZSTR_VAL(name));
6948+
"%s::%s() must be public", ZSTR_VAL(ce->name), ZSTR_VAL(name));
69496949
}
69506950
op_array->fn_flags |= ZEND_ACC_ABSTRACT;
69516951
}

tests/classes/interface_method_private.phpt

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

1010
?>
1111
--EXPECTF--
12-
Fatal error: Access type for interface method if_a::err() must be omitted in %s on line %d
12+
Fatal error: Access type for interface method if_a::err() must be public in %s on line %d

0 commit comments

Comments
 (0)