Error Identifier: argument.duplicate
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.
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);
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]
- 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\ParamAttributesRule [1] [2]
- PHPStan\Rules\Methods\CallMethodsRule [1] [2]
- PHPStan\Rules\Methods\CallStaticMethodsRule [1] [2]
- PHPStan\Rules\Methods\MethodAttributesRule [1] [2]
- PHPStan\Rules\Properties\PropertyAttributesRule [1] [2]
- PHPStan\Rules\Properties\PropertyHookAttributesRule [1] [2]
- PHPStan\Rules\Traits\TraitAttributesRule [1] [2]