From d88b212ea6bad0a1634dea56140a48a11602dd5b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 11 Sep 2019 17:04:13 +0200 Subject: [PATCH] Improve "already declared" error message If this error is missing because the rtd_key was renamed to lcname, fetch the class based on lcname and use the class type and cased name from there. --- Zend/tests/declare_already_in_use.phpt | 14 ++++++++++++++ Zend/zend_compile.c | 9 +++------ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 Zend/tests/declare_already_in_use.phpt diff --git a/Zend/tests/declare_already_in_use.phpt b/Zend/tests/declare_already_in_use.phpt new file mode 100644 index 00000000000..c7e4ce8d677 --- /dev/null +++ b/Zend/tests/declare_already_in_use.phpt @@ -0,0 +1,14 @@ +--TEST-- +Cannot declare class, because the name is already in use +--FILE-- + +--EXPECTF-- +Fatal error: Cannot declare class A, because the name is already in use in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 9099c48193e..fc2efd2e6c5 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1067,12 +1067,9 @@ ZEND_API int do_bind_class(zval *lcname, zend_string *lc_parent_name) /* {{{ */ zv = zend_hash_find_ex(EG(class_table), Z_STR_P(rtd_key), 1); if (UNEXPECTED(!zv)) { - /* If we're in compile time, in practice, it's quite possible - * that we'll never reach this class declaration at runtime, - * so we shut up about it. This allows the if (!defined('FOO')) { return; } - * approach to work. - */ - zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s, because the name is already in use", Z_STRVAL_P(lcname)); + ce = zend_hash_find_ptr(EG(class_table), Z_STR_P(lcname)); + ZEND_ASSERT(ce && "Class with lcname should be registered"); + zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name)); return FAILURE; }