Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
function foo(int $a, int $b, int $c = 3, int $d = 4): int
{
return $a + $b + $c + $d;
}
foo(...[1, 2], b: 20);
Why is it reported? #
Named arguments in PHP must not overwrite a positional argument that was already passed. In the example above, the array unpacking ...[1, 2] passes values to $a and $b positionally, and then b: 20 attempts to pass $b again by name. PHP raises a fatal error at runtime in this case. This error is also reported when the same named parameter is explicitly provided more than once.
It is also reported when a closure created by a partial function application (PHP 8.6+) is called with a named argument for a parameter that the partial application already bound:
<?php declare(strict_types = 1);
function doFoo(int $a, string $b, float $c, bool ...$d): string
{
return '';
}
$f = doFoo(1, ?, ...);
$f('b', 1.0, a: true); // $a is already bound to 1
The parameter $a already received its value when the closure was created, so passing it again by name is a duplicate argument for the underlying function call.
How to fix it #
Remove the duplicate argument so each parameter receives exactly one value:
<?php declare(strict_types = 1);
function foo(int $a, int $b, int $c = 3, int $d = 4): int
{
return $a + $b + $c + $d;
}
-foo(...[1, 2], b: 20);
+foo(...[1, 2], d: 40);
For a partially applied closure, remove the named argument for the bound parameter, or pass the extra variadic argument under a different name:
-$f = doFoo(1, ?, ...);
-$f('b', 1.0, a: true);
+$f = doFoo(1, ?, ...);
+$f('b', 1.0, flag: true);
How to ignore this error #
You can use the identifier argument.duplicate to ignore this error using a comment:
// @phpstan-ignore argument.duplicate
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: argument.duplicate
Rules that report this error #
- PHPStan\Rules\Classes\ClassAttributesRule [1] [2]
- PHPStan\Rules\Classes\ClassConstantAttributesRule [1] [2]
- PHPStan\Rules\Classes\InstantiationRule [1] [2]
- PHPStan\Rules\Constants\ConstantAttributesRule [1] [2]
- PHPStan\Rules\EnumCases\EnumCaseAttributesRule [1] [2]
- PHPStan\Rules\Functions\ArrowFunctionAttributesRule [1] [2]
- PHPStan\Rules\Functions\CallCallablesRule [1] [2] [3]
- PHPStan\Rules\Functions\CallToFunctionParametersRule [1] [2]
- PHPStan\Rules\Functions\CallUserFuncRule [1] [2]
- PHPStan\Rules\Functions\ClosureAttributesRule [1] [2]
- PHPStan\Rules\Functions\FunctionAttributesRule [1] [2]
- PHPStan\Rules\Functions\FunctionCallableRule [1] [2]
- PHPStan\Rules\Functions\ParamAttributesRule [1] [2]
- PHPStan\Rules\Methods\CallMethodsRule [1] [2]
- PHPStan\Rules\Methods\CallStaticMethodsRule [1] [2]
- PHPStan\Rules\Methods\MethodAttributesRule [1] [2]
- PHPStan\Rules\Methods\MethodCallableRule [1] [2]
- PHPStan\Rules\Methods\StaticMethodCallableRule [1] [2]
- PHPStan\Rules\Properties\PropertyAttributesRule [1] [2]
- PHPStan\Rules\Properties\PropertyHookAttributesRule [1] [2]
- PHPStan\Rules\Traits\TraitAttributesRule [1] [2]