From a706d7302a5b545181125da0442455a721ecc4e0 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Wed, 2 Jun 2021 04:16:06 +0530 Subject: [PATCH] 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 --- Zend/tests/bug71871.phpt | 2 +- Zend/tests/bug71871_2.phpt | 2 +- Zend/zend_compile.c | 2 +- tests/classes/interface_method_private.phpt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Zend/tests/bug71871.phpt b/Zend/tests/bug71871.phpt index 1781ff07aa8..981e7519c76 100644 --- a/Zend/tests/bug71871.phpt +++ b/Zend/tests/bug71871.phpt @@ -9,4 +9,4 @@ interface test { ?> --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 diff --git a/Zend/tests/bug71871_2.phpt b/Zend/tests/bug71871_2.phpt index 6a9404ea37d..2781a8d4955 100644 --- a/Zend/tests/bug71871_2.phpt +++ b/Zend/tests/bug71871_2.phpt @@ -9,4 +9,4 @@ interface test { ?> --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 diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ac97499e90b..8be07686a4a 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6945,7 +6945,7 @@ zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name, if (in_interface) { 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 " - "%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; } diff --git a/tests/classes/interface_method_private.phpt b/tests/classes/interface_method_private.phpt index 4661a863758..c7a0852ea4a 100644 --- a/tests/classes/interface_method_private.phpt +++ b/tests/classes/interface_method_private.phpt @@ -9,4 +9,4 @@ interface if_a { ?> --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