Skip to content

Commit 7183717

Browse files
committed
Improve error message for deprecated methods
1 parent 50a9f51 commit 7183717

13 files changed

+68
-54
lines changed

Zend/tests/bug69802_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $r = new ReflectionMethod($f, '__invoke');
77
var_dump($r->getParameters()[0]->getClass());
88
?>
99
--EXPECTF--
10-
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
10+
Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d
1111
object(ReflectionClass)#4 (1) {
1212
["name"]=>
1313
string(11) "Traversable"

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/tests/type_declarations/callable_002.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ var_dump($rc->getParameters()[0]->isCallable());
2121

2222
?>
2323
--EXPECTF--
24-
Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d
24+
Deprecated: Method ReflectionParameter::isCallable() is deprecated in %s on line %d
2525
bool(true)
2626

27-
Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d
27+
Deprecated: Method ReflectionParameter::isCallable() is deprecated in %s on line %d
2828
bool(true)
2929

30-
Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d
30+
Deprecated: Method ReflectionParameter::isCallable() is deprecated in %s on line %d
3131
bool(true)

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);

ext/reflection/tests/ReflectionClass_isArray.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ foreach ($reflection->getParameters() as $parameter) {
1414
}
1515
?>
1616
--EXPECTF--
17-
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
17+
Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d
1818
bool(true)
1919

20-
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
20+
Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d
2121
bool(true)
2222

23-
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
23+
Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d
2424
bool(false)
2525

26-
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
26+
Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d
2727
bool(false)

ext/reflection/tests/ReflectionFunction_isDisabled_basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ var_dump($rf->isDisabled());
2020
--EXPECTF--
2121
Function is_file() does not exist
2222

23-
Deprecated: Function ReflectionFunction::isDisabled() is deprecated in %s on line %d
23+
Deprecated: Method ReflectionFunction::isDisabled() is deprecated in %s on line %d
2424
bool(false)

ext/reflection/tests/bug26695.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ $class = $params[0]->getClass();
2020
var_dump($class->getName());
2121
?>
2222
--EXPECTF--
23-
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
23+
Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d
2424
string(3) "Foo"

ext/reflection/tests/bug29268.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ foreach($parameters as $parameter)
2222
echo "ok\n";
2323
?>
2424
--EXPECTF--
25-
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
25+
Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d
2626
__autoload(A)
2727
A
2828
ok

0 commit comments

Comments
 (0)