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
This commit is contained in:
Ayesh Karunaratne 2021-06-02 04:16:06 +05:30 committed by George Peter Banyard
parent 467801d7bb
commit a706d7302a
4 changed files with 4 additions and 4 deletions

View file

@ -9,4 +9,4 @@ interface test {
?> ?>
--EXPECTF-- --EXPECTF--
Fatal error: Access type for interface method test::test() must be omitted in %s on line %d Fatal error: Access type for interface method test::test() must be public in %s on line %d

View file

@ -9,4 +9,4 @@ interface test {
?> ?>
--EXPECTF-- --EXPECTF--
Fatal error: Access type for interface method test::test() must be omitted in %s on line %d Fatal error: Access type for interface method test::test() must be public in %s on line %d

View file

@ -6945,7 +6945,7 @@ zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name,
if (in_interface) { if (in_interface) {
if (!(fn_flags & ZEND_ACC_PUBLIC) || (fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) { if (!(fn_flags & ZEND_ACC_PUBLIC) || (fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) {
zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method " zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
"%s::%s() must be omitted", ZSTR_VAL(ce->name), ZSTR_VAL(name)); "%s::%s() must be public", ZSTR_VAL(ce->name), ZSTR_VAL(name));
} }
op_array->fn_flags |= ZEND_ACC_ABSTRACT; op_array->fn_flags |= ZEND_ACC_ABSTRACT;
} }

View file

@ -9,4 +9,4 @@ interface if_a {
?> ?>
--EXPECTF-- --EXPECTF--
Fatal error: Access type for interface method if_a::err() must be omitted in %s on line %d Fatal error: Access type for interface method if_a::err() must be public in %s on line %d