Skip to content

Commit 9377f79

Browse files
committed
Improve error message for deprecated methods
1 parent 33c3691 commit 9377f79

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

Zend/tests/bug78239.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $r = new _ZendTestClass;
1616

1717
?>
1818
--EXPECTF--
19-
Fatal error: Uncaught ErrorException: Function _ZendTestClass::__toString() is deprecated in %s:%d
19+
Fatal error: Uncaught ErrorException: Method _ZendTestClass::__toString() is deprecated in %s:%d
2020
Stack trace:
2121
#0 %s(%d): handleError(%s)
2222
#1 {main}

Zend/zend_execute.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,10 +1504,14 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(z
15041504

15051505
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc)
15061506
{
1507-
zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
1508-
fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "",
1509-
fbc->common.scope ? "::" : "",
1510-
ZSTR_VAL(fbc->common.function_name));
1507+
if (fbc->common.scope) {
1508+
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",
1509+
ZSTR_VAL(fbc->common.scope->name),
1510+
ZSTR_VAL(fbc->common.function_name)
1511+
);
1512+
} else {
1513+
zend_error(E_DEPRECATED, "Function %s() is deprecated", ZSTR_VAL(fbc->common.function_name));
1514+
}
15111515
}
15121516

15131517
static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)

Zend/zend_execute_API.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,15 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
722722
func, fci->param_count, object_or_called_scope);
723723

724724
if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_DEPRECATED)) {
725-
zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
726-
func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
727-
func->common.scope ? "::" : "",
728-
ZSTR_VAL(func->common.function_name));
725+
if (func->common.scope) {
726+
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",
727+
ZSTR_VAL(func->common.scope->name),
728+
ZSTR_VAL(func->common.function_name)
729+
);
730+
} else {
731+
zend_error(E_DEPRECATED, "Function %s() is deprecated", ZSTR_VAL(func->common.function_name));
732+
}
733+
729734
if (UNEXPECTED(EG(exception))) {
730735
zend_vm_stack_free_call_frame(call);
731736
if (EG(current_execute_data) == &dummy_execute_data) {

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,15 @@ void ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D)
157157
{
158158
zend_execute_data *call = (zend_execute_data *) opline;
159159
zend_function *fbc = call->func;
160-
zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
161-
fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "",
162-
fbc->common.scope ? "::" : "",
163-
ZSTR_VAL(fbc->common.function_name));
160+
if (fbc->common.scope) {
161+
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",
162+
ZSTR_VAL(fbc->common.scope->name),
163+
ZSTR_VAL(fbc->common.function_name)
164+
);
165+
} else {
166+
zend_error(E_DEPRECATED, "Function %s() is deprecated", ZSTR_VAL(fbc->common.function_name));
167+
}
168+
164169
if (EG(exception)) {
165170
#ifndef HAVE_GCC_GLOBAL_REGS
166171
zend_execute_data *execute_data = EG(current_execute_data);

0 commit comments

Comments
 (0)