From 7d5ff2c8bc411aa59fc9cdfb55931bb0100fd348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Sun, 7 Apr 2024 23:02:21 +0200 Subject: [PATCH] Fix #13865 Improve parameter and return value related deprecation messages --- Zend/tests/bug71428.3.phpt | 2 +- Zend/tests/call_user_func_005.phpt | 2 +- Zend/tests/gh11488.phpt | 6 +++--- Zend/tests/ns_073.phpt | 2 +- Zend/tests/required_param_after_optional.phpt | 12 ++++++------ ...required_param_after_optional_named_args.phpt | 2 +- Zend/tests/return_by_ref_from_void_function.phpt | 2 +- Zend/tests/traits/bug60717.phpt | 6 +++--- Zend/tests/type_declarations/callable_003.phpt | 2 +- .../implicit_nullable_intersection_type.phpt | 2 +- ...mplicit_nullable_intersection_type_error.phpt | 2 +- .../type_declarations/iterable/iterable_002.phpt | 2 +- .../false_standalone_implicit_nullability.phpt | 2 +- .../true_standalone_implicit_nullability.phpt | 2 +- Zend/tests/type_declarations/nullable_null.phpt | 2 +- Zend/zend_compile.c | 16 +++++++++++----- .../tests/ReflectionClass_export_basic1.phpt | 2 +- ext/reflection/tests/bug62715.phpt | 4 ++-- ext/reflection/tests/parameters_002.phpt | 2 +- .../tests/types/ReflectionType_001.phpt | 2 +- ...re_intersection_type_implicitly_nullable.phpt | 2 +- tests/classes/type_hinting_003.phpt | 2 +- tests/classes/type_hinting_004.phpt | 6 +++--- tests/lang/type_hints_002.phpt | 2 +- 24 files changed, 46 insertions(+), 40 deletions(-) diff --git a/Zend/tests/bug71428.3.phpt b/Zend/tests/bug71428.3.phpt index ceaa5dae0f2a7..b24ce3675156e 100644 --- a/Zend/tests/bug71428.3.phpt +++ b/Zend/tests/bug71428.3.phpt @@ -7,6 +7,6 @@ class B { public function m(A $a = NULL, $n) { echo "B.m";} }; class C extends B { public function m(A $a , $n) { echo "C.m";} }; ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: B::m(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d 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 diff --git a/Zend/tests/call_user_func_005.phpt b/Zend/tests/call_user_func_005.phpt index 6a32f1970b563..656d9af636d94 100644 --- a/Zend/tests/call_user_func_005.phpt +++ b/Zend/tests/call_user_func_005.phpt @@ -18,7 +18,7 @@ var_dump(call_user_func(array('foo', 'teste'))); ?> --EXPECTF-- -Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d +Deprecated: {closure}(): Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d string(1) "x" array(1) { [0]=> diff --git a/Zend/tests/gh11488.phpt b/Zend/tests/gh11488.phpt index e499656806319..587734c85cf5c 100644 --- a/Zend/tests/gh11488.phpt +++ b/Zend/tests/gh11488.phpt @@ -16,8 +16,8 @@ function c( ) {} ?> --EXPECTF-- -Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d +Deprecated: a(): Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d -Deprecated: Implicitly marking parameter $c as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: b(): Implicitly marking parameter $c as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d -Deprecated: Optional parameter $e declared before required parameter $f is implicitly treated as a required parameter in %s on line %d +Deprecated: c(): Optional parameter $e declared before required parameter $f is implicitly treated as a required parameter in %s on line %d diff --git a/Zend/tests/ns_073.phpt b/Zend/tests/ns_073.phpt index 0d8f3f3b95ca5..c2bacc858e807 100644 --- a/Zend/tests/ns_073.phpt +++ b/Zend/tests/ns_073.phpt @@ -14,7 +14,7 @@ $x(new \stdclass); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $x as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: foo\{closure}(): Implicitly marking parameter $x as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d NULL object(stdClass)#%d (0) { } diff --git a/Zend/tests/required_param_after_optional.phpt b/Zend/tests/required_param_after_optional.phpt index 6b9d7610805e1..00dc473e96ab5 100644 --- a/Zend/tests/required_param_after_optional.phpt +++ b/Zend/tests/required_param_after_optional.phpt @@ -9,14 +9,14 @@ function test3(Type $test3A = null, ?Type2 $test3B = null, $test3C) {} ?> --EXPECTF-- -Deprecated: Optional parameter $testA declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d +Deprecated: test(): Optional parameter $testA declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d -Deprecated: Optional parameter $testB declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d +Deprecated: test(): Optional parameter $testB declared before required parameter $testC is implicitly treated as a required parameter in %s on line %d -Deprecated: Implicitly marking parameter $test2A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: test2(): Implicitly marking parameter $test2A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d -Deprecated: Optional parameter $test2B declared before required parameter $test2C is implicitly treated as a required parameter in %s on line %d +Deprecated: test2(): Optional parameter $test2B declared before required parameter $test2C is implicitly treated as a required parameter in %s on line %d -Deprecated: Implicitly marking parameter $test3A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: test3(): Implicitly marking parameter $test3A as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d -Deprecated: Optional parameter $test3B declared before required parameter $test3C is implicitly treated as a required parameter in %s on line %d +Deprecated: test3(): Optional parameter $test3B declared before required parameter $test3C is implicitly treated as a required parameter in %s on line %d diff --git a/Zend/tests/required_param_after_optional_named_args.phpt b/Zend/tests/required_param_after_optional_named_args.phpt index e504d76c7efed..19060ab108b0b 100644 --- a/Zend/tests/required_param_after_optional_named_args.phpt +++ b/Zend/tests/required_param_after_optional_named_args.phpt @@ -13,5 +13,5 @@ try { ?> --EXPECTF-- -Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d +Deprecated: test(): Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter in %s on line %d test(): Argument #1 ($a) not passed diff --git a/Zend/tests/return_by_ref_from_void_function.phpt b/Zend/tests/return_by_ref_from_void_function.phpt index e83e72453e499..a6c06f0d29140 100644 --- a/Zend/tests/return_by_ref_from_void_function.phpt +++ b/Zend/tests/return_by_ref_from_void_function.phpt @@ -11,7 +11,7 @@ var_dump($r); ?> --EXPECTF-- -Deprecated: Returning by reference from a void function is deprecated in %s on line %d +Deprecated: test(): Returning by reference from a void function is deprecated in %s on line %d Notice: Only variable references should be returned by reference in %s on line %d NULL diff --git a/Zend/tests/traits/bug60717.phpt b/Zend/tests/traits/bug60717.phpt index d713f36acdb3e..71145385422f3 100644 --- a/Zend/tests/traits/bug60717.phpt +++ b/Zend/tests/traits/bug60717.phpt @@ -70,9 +70,9 @@ namespace HTML } ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +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 -Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +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 -Deprecated: Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +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 Done diff --git a/Zend/tests/type_declarations/callable_003.phpt b/Zend/tests/type_declarations/callable_003.phpt index c266fe13c35ff..f489f286d06e1 100644 --- a/Zend/tests/type_declarations/callable_003.phpt +++ b/Zend/tests/type_declarations/callable_003.phpt @@ -14,7 +14,7 @@ foo("strpos", 123, "strpos"); bar("substr"); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: bar(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d string(6) "strpos" int(123) string(6) "strpos" diff --git a/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type.phpt b/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type.phpt index 4efea911e3d9f..5b6266a2142a9 100644 --- a/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type.phpt +++ b/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type.phpt @@ -11,5 +11,5 @@ foo(null); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: foo(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d NULL diff --git a/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type_error.phpt b/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type_error.phpt index bd2bc272e90f0..83af5e96ccfac 100644 --- a/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type_error.phpt +++ b/Zend/tests/type_declarations/intersection_types/implicit_nullable_intersection_type_error.phpt @@ -15,5 +15,5 @@ try { ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: foo(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d foo(): Argument #1 ($foo) must be of type (X&Y)|null, int given, called in %s on line %d diff --git a/Zend/tests/type_declarations/iterable/iterable_002.phpt b/Zend/tests/type_declarations/iterable/iterable_002.phpt index 3affb4ade7339..4e42d46f69eec 100644 --- a/Zend/tests/type_declarations/iterable/iterable_002.phpt +++ b/Zend/tests/type_declarations/iterable/iterable_002.phpt @@ -17,6 +17,6 @@ function baz(iterable $iterable = 1) { ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $iterable as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: foo(): Implicitly marking parameter $iterable as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d Fatal error: Cannot use int as default value for parameter $iterable of type Traversable|array in %s on line %d diff --git a/Zend/tests/type_declarations/literal_types/false_standalone_implicit_nullability.phpt b/Zend/tests/type_declarations/literal_types/false_standalone_implicit_nullability.phpt index 66884dcbe6d1e..fb2253ca03367 100644 --- a/Zend/tests/type_declarations/literal_types/false_standalone_implicit_nullability.phpt +++ b/Zend/tests/type_declarations/literal_types/false_standalone_implicit_nullability.phpt @@ -9,6 +9,6 @@ var_dump(test(false)); var_dump(test(null)); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: test(): Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d bool(false) NULL diff --git a/Zend/tests/type_declarations/literal_types/true_standalone_implicit_nullability.phpt b/Zend/tests/type_declarations/literal_types/true_standalone_implicit_nullability.phpt index 8905fb9e5b94b..c776cbb1d5a5c 100644 --- a/Zend/tests/type_declarations/literal_types/true_standalone_implicit_nullability.phpt +++ b/Zend/tests/type_declarations/literal_types/true_standalone_implicit_nullability.phpt @@ -9,6 +9,6 @@ var_dump(test(true)); var_dump(test(null)); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: test(): Implicitly marking parameter $v as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d bool(true) NULL diff --git a/Zend/tests/type_declarations/nullable_null.phpt b/Zend/tests/type_declarations/nullable_null.phpt index 04e3e50c42aad..a89f1a0d34c0f 100644 --- a/Zend/tests/type_declarations/nullable_null.phpt +++ b/Zend/tests/type_declarations/nullable_null.phpt @@ -8,5 +8,5 @@ function test(Foo $a = null) { test(null); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: test(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d ok diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 4077ef4ef080a..782773cb56db0 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7126,7 +7126,9 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32 if (ZEND_TYPE_CONTAINS_CODE(arg_infos[-1].type, IS_VOID) && (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) { - zend_error(E_DEPRECATED, "Returning by reference from a void function is deprecated"); + zend_string *func_name = get_function_or_method_name((zend_function *) op_array); + zend_error(E_DEPRECATED, "%s(): Returning by reference from a void function is deprecated", ZSTR_VAL(func_name)); + zend_string_release(func_name); } } else { if (list->children == 0) { @@ -7225,9 +7227,11 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32 op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS; arg_info->type = zend_compile_typename_ex(type_ast, force_nullable, &forced_allow_nullable); if (forced_allow_nullable) { + zend_string *func_name = get_function_or_method_name((zend_function *) op_array); zend_error(E_DEPRECATED, - "Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type " - "must be used instead", ZSTR_VAL(name)); + "%s(): Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type " + "must be used instead", ZSTR_VAL(func_name), ZSTR_VAL(name)); + zend_string_release(func_name); } 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 /* Ignore parameters of the form "Type $param = null". * This is the PHP 5 style way of writing "?Type $param", so allow it for now. */ if (!forced_allow_nullable) { + zend_string *func_name = get_function_or_method_name((zend_function *) op_array); zend_ast *required_param_ast = list->child[last_required_param]; zend_error(E_DEPRECATED, - "Optional parameter $%s declared before required parameter $%s " + "%s(): Optional parameter $%s declared before required parameter $%s " "is implicitly treated as a required parameter", - ZSTR_VAL(name), ZSTR_VAL(zend_ast_get_str(required_param_ast->child[1]))); + ZSTR_VAL(func_name), ZSTR_VAL(name), ZSTR_VAL(zend_ast_get_str(required_param_ast->child[1]))); + zend_string_release(func_name); } /* Regardless of whether we issue a deprecation, convert this parameter into diff --git a/ext/reflection/tests/ReflectionClass_export_basic1.phpt b/ext/reflection/tests/ReflectionClass_export_basic1.phpt index 0931e5e123064..91c3e1567c838 100644 --- a/ext/reflection/tests/ReflectionClass_export_basic1.phpt +++ b/ext/reflection/tests/ReflectionClass_export_basic1.phpt @@ -20,7 +20,7 @@ define('K', "16 chars long --"); echo new ReflectionClass("C"), "\n"; ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $h as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: A::pubf(): Implicitly marking parameter $h as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d Class [ class C extends A ] { @@ %s 14-14 diff --git a/ext/reflection/tests/bug62715.phpt b/ext/reflection/tests/bug62715.phpt index e8eecf5c41179..f357983cff2c0 100644 --- a/ext/reflection/tests/bug62715.phpt +++ b/ext/reflection/tests/bug62715.phpt @@ -17,9 +17,9 @@ foreach ($r->getParameters() as $p) { } ?> --EXPECTF-- -Deprecated: Optional parameter $a declared before required parameter $c is implicitly treated as a required parameter in %s on line %d +Deprecated: test(): Optional parameter $a declared before required parameter $c is implicitly treated as a required parameter in %s on line %d -Deprecated: Optional parameter $b declared before required parameter $c is implicitly treated as a required parameter in %s on line %d +Deprecated: test(): Optional parameter $b declared before required parameter $c is implicitly treated as a required parameter in %s on line %d bool(false) bool(false) bool(false) diff --git a/ext/reflection/tests/parameters_002.phpt b/ext/reflection/tests/parameters_002.phpt index 0ace42b100a4a..71d58c486f0b0 100644 --- a/ext/reflection/tests/parameters_002.phpt +++ b/ext/reflection/tests/parameters_002.phpt @@ -73,7 +73,7 @@ check_params(ReflectionMethod::createFromMethodName('test::method')); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $opt as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: test(): Implicitly marking parameter $opt as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d #####test()##### ===0=== getName: string(3) "nix" diff --git a/ext/reflection/tests/types/ReflectionType_001.phpt b/ext/reflection/tests/types/ReflectionType_001.phpt index 4791be9aef6ca..3441878f155d7 100644 --- a/ext/reflection/tests/types/ReflectionType_001.phpt +++ b/ext/reflection/tests/types/ReflectionType_001.phpt @@ -101,7 +101,7 @@ $r = (new ReflectionProperty($obj, 'std'))->getType(); var_dump($r->getName()); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $d as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: foo(): Implicitly marking parameter $d as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d *** functions ** Function 0 - Parameter 0 bool(true) diff --git a/ext/reflection/tests/types/pure_intersection_type_implicitly_nullable.phpt b/ext/reflection/tests/types/pure_intersection_type_implicitly_nullable.phpt index 3cad1b3ba255c..0d375782592a7 100644 --- a/ext/reflection/tests/types/pure_intersection_type_implicitly_nullable.phpt +++ b/ext/reflection/tests/types/pure_intersection_type_implicitly_nullable.phpt @@ -25,7 +25,7 @@ dumpType((new ReflectionFunction('foo'))->getParameters()[0]->getType()); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: foo(): Implicitly marking parameter $foo as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d Type (X&Y)|null is ReflectionUnionType: Allows Null: true Type X&Y is ReflectionIntersectionType: diff --git a/tests/classes/type_hinting_003.phpt b/tests/classes/type_hinting_003.phpt index 72a31190cfe71..1c1f687c2c005 100644 --- a/tests/classes/type_hinting_003.phpt +++ b/tests/classes/type_hinting_003.phpt @@ -39,7 +39,7 @@ Test::f1(1); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $ar as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: Test::f2(): Implicitly marking parameter $ar as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d Test::f1() array(1) { [0]=> diff --git a/tests/classes/type_hinting_004.phpt b/tests/classes/type_hinting_004.phpt index 7983f09333b55..8d2297ab93ae1 100644 --- a/tests/classes/type_hinting_004.phpt +++ b/tests/classes/type_hinting_004.phpt @@ -143,11 +143,11 @@ Ensure type hints are enforced for functions invoked as callbacks. ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: f2(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d -Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: C::f2(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d -Deprecated: Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: D::f2(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d ---> Type hints with callback function: 0: f1(): Argument #1 ($a) must be of type A, int given%s(%d) diff --git a/tests/lang/type_hints_002.phpt b/tests/lang/type_hints_002.phpt index 8110c0d095cc4..e3c327aab63c1 100644 --- a/tests/lang/type_hints_002.phpt +++ b/tests/lang/type_hints_002.phpt @@ -16,7 +16,7 @@ $o->f(); $o->f(NULL); ?> --EXPECTF-- -Deprecated: Implicitly marking parameter $p as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d +Deprecated: T::f(): Implicitly marking parameter $p as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d object(P)#2 (0) { } -