Skip to content

Fix #13865 Improve parameter and return value related deprecation mesages #13913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/bug71428.3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/call_user_func_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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]=>
Expand Down
6 changes: 3 additions & 3 deletions Zend/tests/gh11488.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/ns_073.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
12 changes: 6 additions & 6 deletions Zend/tests/required_param_after_optional.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/required_param_after_optional_named_args.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/return_by_ref_from_void_function.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions Zend/tests/traits/bug60717.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/type_declarations/callable_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/type_declarations/iterable/iterable_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/type_declarations/nullable_null.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 11 additions & 5 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/tests/ReflectionClass_export_basic1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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 [ <user> class C extends A ] {
@@ %s 14-14

Expand Down
4 changes: 2 additions & 2 deletions ext/reflection/tests/bug62715.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ext/reflection/tests/parameters_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/tests/types/ReflectionType_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/classes/type_hinting_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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]=>
Expand Down
6 changes: 3 additions & 3 deletions tests/classes/type_hinting_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/lang/type_hints_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
-
Expand Down