Skip to content

Commit 2079da0

Browse files
authored
Fix #13865 Improve parameter and return value related deprecation messages (#13913)
I added the function/method name to some compile-time deprecation messages which are related to parameters/return values. Consistently with the other similar error messages, I included the function/method name at the start of the message.
1 parent 0bc5cb6 commit 2079da0

24 files changed

+46
-40
lines changed

Zend/tests/bug71428.3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class B { public function m(A $a = NULL, $n) { echo "B.m";} };
77
class C extends B { public function m(A $a , $n) { echo "C.m";} };
88
?>
99
--EXPECTF--
10-
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
10+
Deprecated: B::m(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1111

1212
Fatal error: Declaration of C::m(A $a, $n) must be compatible with B::m(?A $a, $n) in %sbug71428.3.php on line 4

Zend/tests/call_user_func_005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var_dump(call_user_func(array('foo', 'teste')));
1818

1919
?>
2020
--EXPECTF--
21-
Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
21+
Deprecated: {closure}(): Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
2222
string(1) "x"
2323
array(1) {
2424
[0]=>

Zend/tests/gh11488.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function c(
1616
) {}
1717
?>
1818
--EXPECTF--
19-
Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
19+
Deprecated: a(): Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
2020

21-
Deprecated: Implicitly marking parameter $c as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
21+
Deprecated: b(): Implicitly marking parameter $c as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
2222

23-
Deprecated: Optional parameter $e declared before required parameter $f is implicitly treated as a required parameter in %s on line %d
23+
Deprecated: c(): Optional parameter $e declared before required parameter $f is implicitly treated as a required parameter in %s on line %d

Zend/tests/ns_073.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $x(new \stdclass);
1414

1515
?>
1616
--EXPECTF--
17-
Deprecated: Implicitly marking parameter $x as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
17+
Deprecated: foo\{closure}(): Implicitly marking parameter $x as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1818
NULL
1919
object(stdClass)#%d (0) {
2020
}

Zend/tests/required_param_after_optional.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ function test3(Type $test3A = null, ?Type2 $test3B = null, $test3C) {}
99

1010
?>
1111
--EXPECTF--
12-
Deprecated: Optional parameter $testA declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d
12+
Deprecated: test(): Optional parameter $testA declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d
1313

14-
Deprecated: Optional parameter $testB declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d
14+
Deprecated: test(): Optional parameter $testB declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d
1515

16-
Deprecated: Implicitly marking parameter $test2A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
16+
Deprecated: test2(): Implicitly marking parameter $test2A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1717

18-
Deprecated: Optional parameter $test2B declared before required parameter $test2C is implicitly treated as a required parameter in %s on line %d
18+
Deprecated: test2(): Optional parameter $test2B declared before required parameter $test2C is implicitly treated as a required parameter in %s on line %d
1919

20-
Deprecated: Implicitly marking parameter $test3A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
20+
Deprecated: test3(): Implicitly marking parameter $test3A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
2121

22-
Deprecated: Optional parameter $test3B declared before required parameter $test3C is implicitly treated as a required parameter in %s on line %d
22+
Deprecated: test3(): Optional parameter $test3B declared before required parameter $test3C is implicitly treated as a required parameter in %s on line %d

Zend/tests/required_param_after_optional_named_args.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ try {
1313

1414
?>
1515
--EXPECTF--
16-
Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
16+
Deprecated: test(): Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d
1717
test(): Argument #1 ($a) not passed

Zend/tests/return_by_ref_from_void_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var_dump($r);
1111

1212
?>
1313
--EXPECTF--
14-
Deprecated: Returning by reference from a void function is deprecated in %s on line %d
14+
Deprecated: test(): Returning by reference from a void function is deprecated in %s on line %d
1515

1616
Notice: Only variable references should be returned by reference in %s on line %d
1717
NULL

Zend/tests/traits/bug60717.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ namespace HTML
7070
}
7171
?>
7272
--EXPECTF--
73-
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
73+
Deprecated: HTML\Helper::attributes(): Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
7474

75-
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
75+
Deprecated: HTML\TextArea::attributes(): Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
7676

77-
Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
77+
Deprecated: HTML\HTMLAttributes::attributes(): Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
7878
Done

Zend/tests/type_declarations/callable_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ foo("strpos", 123, "strpos");
1414
bar("substr");
1515
?>
1616
--EXPECTF--
17-
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
17+
Deprecated: bar(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1818
string(6) "strpos"
1919
int(123)
2020
string(6) "strpos"

Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ foo(null);
1111

1212
?>
1313
--EXPECTF--
14-
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
14+
Deprecated: foo(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1515
NULL

Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ try {
1515

1616
?>
1717
--EXPECTF--
18-
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
18+
Deprecated: foo(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1919
foo(): Argument #1 ($foo) must be of type (X&Y)|null, int given, called in %s on line %d

Zend/tests/type_declarations/iterable/iterable_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ function baz(iterable $iterable = 1) {
1717

1818
?>
1919
--EXPECTF--
20-
Deprecated: Implicitly marking parameter $iterable as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
20+
Deprecated: foo(): Implicitly marking parameter $iterable as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
2121

2222
Fatal error: Cannot use int as default value for parameter $iterable of type Traversable|array in %s on line %d

Zend/tests/type_declarations/literal_types/false_standalone_implicit_nullability.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ var_dump(test(false));
99
var_dump(test(null));
1010
?>
1111
--EXPECTF--
12-
Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
12+
Deprecated: test(): Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1313
bool(false)
1414
NULL

Zend/tests/type_declarations/literal_types/true_standalone_implicit_nullability.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ var_dump(test(true));
99
var_dump(test(null));
1010
?>
1111
--EXPECTF--
12-
Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
12+
Deprecated: test(): Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1313
bool(true)
1414
NULL

Zend/tests/type_declarations/nullable_null.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ function test(Foo $a = null) {
88
test(null);
99
?>
1010
--EXPECTF--
11-
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
11+
Deprecated: test(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
1212
ok

Zend/zend_compile.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7126,7 +7126,9 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
71267126

71277127
if (ZEND_TYPE_CONTAINS_CODE(arg_infos[-1].type, IS_VOID)
71287128
&& (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
7129-
zend_error(E_DEPRECATED, "Returning by reference from a void function is deprecated");
7129+
zend_string *func_name = get_function_or_method_name((zend_function *) op_array);
7130+
zend_error(E_DEPRECATED, "%s(): Returning by reference from a void function is deprecated", ZSTR_VAL(func_name));
7131+
zend_string_release(func_name);
71307132
}
71317133
} else {
71327134
if (list->children == 0) {
@@ -7225,9 +7227,11 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
72257227
op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
72267228
arg_info->type = zend_compile_typename_ex(type_ast, force_nullable, &forced_allow_nullable);
72277229
if (forced_allow_nullable) {
7230+
zend_string *func_name = get_function_or_method_name((zend_function *) op_array);
72287231
zend_error(E_DEPRECATED,
7229-
"Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type "
7230-
"must be used instead", ZSTR_VAL(name));
7232+
"%s(): Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type "
7233+
"must be used instead", ZSTR_VAL(func_name), ZSTR_VAL(name));
7234+
zend_string_release(func_name);
72317235
}
72327236

72337237
if (ZEND_TYPE_FULL_MASK(arg_info->type) & MAY_BE_VOID) {
@@ -7253,11 +7257,13 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
72537257
/* Ignore parameters of the form "Type $param = null".
72547258
* This is the PHP 5 style way of writing "?Type $param", so allow it for now. */
72557259
if (!forced_allow_nullable) {
7260+
zend_string *func_name = get_function_or_method_name((zend_function *) op_array);
72567261
zend_ast *required_param_ast = list->child[last_required_param];
72577262
zend_error(E_DEPRECATED,
7258-
"Optional parameter $%s declared before required parameter $%s "
7263+
"%s(): Optional parameter $%s declared before required parameter $%s "
72597264
"is implicitly treated as a required parameter",
7260-
ZSTR_VAL(name), ZSTR_VAL(zend_ast_get_str(required_param_ast->child[1])));
7265+
ZSTR_VAL(func_name), ZSTR_VAL(name), ZSTR_VAL(zend_ast_get_str(required_param_ast->child[1])));
7266+
zend_string_release(func_name);
72617267
}
72627268

72637269
/* Regardless of whether we issue a deprecation, convert this parameter into

ext/reflection/tests/ReflectionClass_export_basic1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define('K', "16 chars long --");
2020
echo new ReflectionClass("C"), "\n";
2121
?>
2222
--EXPECTF--
23-
Deprecated: Implicitly marking parameter $h as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
23+
Deprecated: A::pubf(): Implicitly marking parameter $h as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
2424
Class [ <user> class C extends A ] {
2525
@@ %s 14-14
2626

ext/reflection/tests/bug62715.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ foreach ($r->getParameters() as $p) {
1717
}
1818
?>
1919
--EXPECTF--
20-
Deprecated: Optional parameter $a declared before required parameter $c is implicitly treated as a required parameter in %s on line %d
20+
Deprecated: test(): Optional parameter $a declared before required parameter $c is implicitly treated as a required parameter in %s on line %d
2121

22-
Deprecated: Optional parameter $b declared before required parameter $c is implicitly treated as a required parameter in %s on line %d
22+
Deprecated: test(): Optional parameter $b declared before required parameter $c is implicitly treated as a required parameter in %s on line %d
2323
bool(false)
2424
bool(false)
2525
bool(false)

ext/reflection/tests/parameters_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ check_params(ReflectionMethod::createFromMethodName('test::method'));
7373

7474
?>
7575
--EXPECTF--
76-
Deprecated: Implicitly marking parameter $opt as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
76+
Deprecated: test(): Implicitly marking parameter $opt as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
7777
#####test()#####
7878
===0===
7979
getName: string(3) "nix"

ext/reflection/tests/types/ReflectionType_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ $r = (new ReflectionProperty($obj, 'std'))->getType();
101101
var_dump($r->getName());
102102
?>
103103
--EXPECTF--
104-
Deprecated: Implicitly marking parameter $d as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
104+
Deprecated: foo(): Implicitly marking parameter $d as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
105105
*** functions
106106
** Function 0 - Parameter 0
107107
bool(true)

ext/reflection/tests/types/pure_intersection_type_implicitly_nullable.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dumpType((new ReflectionFunction('foo'))->getParameters()[0]->getType());
2525

2626
?>
2727
--EXPECTF--
28-
Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
28+
Deprecated: foo(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
2929
Type (X&Y)|null is ReflectionUnionType:
3030
Allows Null: true
3131
Type X&Y is ReflectionIntersectionType:

tests/classes/type_hinting_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Test::f1(1);
3939

4040
?>
4141
--EXPECTF--
42-
Deprecated: Implicitly marking parameter $ar as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
42+
Deprecated: Test::f2(): Implicitly marking parameter $ar as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
4343
Test::f1()
4444
array(1) {
4545
[0]=>

tests/classes/type_hinting_004.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ Ensure type hints are enforced for functions invoked as callbacks.
143143

144144
?>
145145
--EXPECTF--
146-
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
146+
Deprecated: f2(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
147147

148-
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
148+
Deprecated: C::f2(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
149149

150-
Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
150+
Deprecated: D::f2(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
151151
---> Type hints with callback function:
152152
0: f1(): Argument #1 ($a) must be of type A, int given%s(%d)
153153

tests/lang/type_hints_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $o->f();
1616
$o->f(NULL);
1717
?>
1818
--EXPECTF--
19-
Deprecated: Implicitly marking parameter $p as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
19+
Deprecated: T::f(): Implicitly marking parameter $p as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d
2020
object(P)#2 (0) {
2121
}
2222
-

0 commit comments

Comments
 (0)