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.
This commit is contained in:
Máté Kocsis 2024-04-08 22:20:32 +02:00 committed by GitHub
parent 0bc5cb625e
commit 2079da0158
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 46 additions and 40 deletions

View file

@ -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";} }; class C extends B { public function m(A $a , $n) { echo "C.m";} };
?> ?>
--EXPECTF-- --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 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

View file

@ -18,7 +18,7 @@ var_dump(call_user_func(array('foo', 'teste')));
?> ?>
--EXPECTF-- --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" string(1) "x"
array(1) { array(1) {
[0]=> [0]=>

View file

@ -16,8 +16,8 @@ function c(
) {} ) {}
?> ?>
--EXPECTF-- --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

View file

@ -14,7 +14,7 @@ $x(new \stdclass);
?> ?>
--EXPECTF-- --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 NULL
object(stdClass)#%d (0) { object(stdClass)#%d (0) {
} }

View file

@ -9,14 +9,14 @@ function test3(Type $test3A = null, ?Type2 $test3B = null, $test3C) {}
?> ?>
--EXPECTF-- --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

View file

@ -13,5 +13,5 @@ try {
?> ?>
--EXPECTF-- --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 test(): Argument #1 ($a) not passed

View file

@ -11,7 +11,7 @@ var_dump($r);
?> ?>
--EXPECTF-- --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 Notice: Only variable references should be returned by reference in %s on line %d
NULL NULL

View file

@ -70,9 +70,9 @@ namespace HTML
} }
?> ?>
--EXPECTF-- --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 Done

View file

@ -14,7 +14,7 @@ foo("strpos", 123, "strpos");
bar("substr"); bar("substr");
?> ?>
--EXPECTF-- --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" string(6) "strpos"
int(123) int(123)
string(6) "strpos" string(6) "strpos"

View file

@ -11,5 +11,5 @@ foo(null);
?> ?>
--EXPECTF-- --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 NULL

View file

@ -15,5 +15,5 @@ try {
?> ?>
--EXPECTF-- --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 foo(): Argument #1 ($foo) must be of type (X&Y)|null, int given, called in %s on line %d

View file

@ -17,6 +17,6 @@ function baz(iterable $iterable = 1) {
?> ?>
--EXPECTF-- --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 Fatal error: Cannot use int as default value for parameter $iterable of type Traversable|array in %s on line %d

View file

@ -9,6 +9,6 @@ var_dump(test(false));
var_dump(test(null)); var_dump(test(null));
?> ?>
--EXPECTF-- --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) bool(false)
NULL NULL

View file

@ -9,6 +9,6 @@ var_dump(test(true));
var_dump(test(null)); var_dump(test(null));
?> ?>
--EXPECTF-- --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) bool(true)
NULL NULL

View file

@ -8,5 +8,5 @@ function test(Foo $a = null) {
test(null); test(null);
?> ?>
--EXPECTF-- --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 ok

View file

@ -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) if (ZEND_TYPE_CONTAINS_CODE(arg_infos[-1].type, IS_VOID)
&& (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) { && (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 { } else {
if (list->children == 0) { 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; op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
arg_info->type = zend_compile_typename_ex(type_ast, force_nullable, &forced_allow_nullable); arg_info->type = zend_compile_typename_ex(type_ast, force_nullable, &forced_allow_nullable);
if (forced_allow_nullable) { if (forced_allow_nullable) {
zend_string *func_name = get_function_or_method_name((zend_function *) op_array);
zend_error(E_DEPRECATED, zend_error(E_DEPRECATED,
"Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type " "%s(): Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type "
"must be used instead", ZSTR_VAL(name)); "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) { 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". /* Ignore parameters of the form "Type $param = null".
* This is the PHP 5 style way of writing "?Type $param", so allow it for now. */ * This is the PHP 5 style way of writing "?Type $param", so allow it for now. */
if (!forced_allow_nullable) { 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_ast *required_param_ast = list->child[last_required_param];
zend_error(E_DEPRECATED, 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", "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 /* Regardless of whether we issue a deprecation, convert this parameter into

View file

@ -20,7 +20,7 @@ define('K', "16 chars long --");
echo new ReflectionClass("C"), "\n"; echo new ReflectionClass("C"), "\n";
?> ?>
--EXPECTF-- --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 ] { Class [ <user> class C extends A ] {
@@ %s 14-14 @@ %s 14-14

View file

@ -17,9 +17,9 @@ foreach ($r->getParameters() as $p) {
} }
?> ?>
--EXPECTF-- --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) bool(false)
bool(false) bool(false)

View file

@ -73,7 +73,7 @@ check_params(ReflectionMethod::createFromMethodName('test::method'));
?> ?>
--EXPECTF-- --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()##### #####test()#####
===0=== ===0===
getName: string(3) "nix" getName: string(3) "nix"

View file

@ -101,7 +101,7 @@ $r = (new ReflectionProperty($obj, 'std'))->getType();
var_dump($r->getName()); var_dump($r->getName());
?> ?>
--EXPECTF-- --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 *** functions
** Function 0 - Parameter 0 ** Function 0 - Parameter 0
bool(true) bool(true)

View file

@ -25,7 +25,7 @@ dumpType((new ReflectionFunction('foo'))->getParameters()[0]->getType());
?> ?>
--EXPECTF-- --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: Type (X&Y)|null is ReflectionUnionType:
Allows Null: true Allows Null: true
Type X&Y is ReflectionIntersectionType: Type X&Y is ReflectionIntersectionType:

View file

@ -39,7 +39,7 @@ Test::f1(1);
?> ?>
--EXPECTF-- --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() Test::f1()
array(1) { array(1) {
[0]=> [0]=>

View file

@ -143,11 +143,11 @@ Ensure type hints are enforced for functions invoked as callbacks.
?> ?>
--EXPECTF-- --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: ---> Type hints with callback function:
0: f1(): Argument #1 ($a) must be of type A, int given%s(%d) 0: f1(): Argument #1 ($a) must be of type A, int given%s(%d)

View file

@ -16,7 +16,7 @@ $o->f();
$o->f(NULL); $o->f(NULL);
?> ?>
--EXPECTF-- --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) { object(P)#2 (0) {
} }
- -