Error Identifier: argument.type
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 greet(string $name): void
{
}
greet(123);
Why is it reported? #
The type of an argument passed to a function or method does not match the expected parameter type. PHP would either throw a TypeError at runtime or perform an implicit type coercion, depending on strict types mode.
In the example above, an int is passed where a string is expected.
How to fix it #
Pass a value of the correct type:
<?php declare(strict_types = 1);
function greet(string $name): void
{
}
-greet(123);
+greet('Alice');
Or convert the value to the expected type before passing it:
-greet(123);
+greet((string) 123);
If the function should accept multiple types, update its parameter type declaration:
-function greet(string $name): void
+function greet(string|int $name): void
{
}
How to ignore this error #
You can use the identifier argument.type to ignore this error using a comment:
// @phpstan-ignore argument.type
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.type
Rules that report this error #
- PHPStan\Rules\Classes\ClassAttributesRule [1]
- PHPStan\Rules\Classes\ClassConstantAttributesRule [1]
- PHPStan\Rules\Classes\InstantiationRule [1]
- PHPStan\Rules\Constants\ConstantAttributesRule [1]
- PHPStan\Rules\EnumCases\EnumCaseAttributesRule [1]
- PHPStan\Rules\Functions\ArrowFunctionAttributesRule [1]
- PHPStan\Rules\Functions\CallCallablesRule [1]
- PHPStan\Rules\Functions\CallToFunctionParametersRule [1]
- PHPStan\Rules\Functions\CallUserFuncRule [1]
- PHPStan\Rules\Functions\ClosureAttributesRule [1]
- PHPStan\Rules\Functions\FunctionAttributesRule [1]
- PHPStan\Rules\Functions\ImplodeParameterCastableToStringRule [1]
- PHPStan\Rules\Functions\ParamAttributesRule [1]
- PHPStan\Rules\Functions\ParameterCastableToNumberRule [1]
- PHPStan\Rules\Functions\ParameterCastableToStringRule [1]
- PHPStan\Rules\Functions\PrintfParameterTypeRule [1]
- PHPStan\Rules\Functions\RandomIntParametersRule [1]
- PHPStan\Rules\Functions\SortParameterCastableToStringRule [1]
- PHPStan\Rules\Methods\CallMethodsRule [1]
- PHPStan\Rules\Methods\CallStaticMethodsRule [1]
- PHPStan\Rules\Methods\MethodAttributesRule [1]
- PHPStan\Rules\Properties\PropertyAttributesRule [1]
- PHPStan\Rules\Properties\PropertyHookAttributesRule [1]
- PHPStan\Rules\Symfony\InvalidArgumentDefaultValueRule [1] [2] phpstan/phpstan-symfony
- PHPStan\Rules\Symfony\InvalidOptionDefaultValueRule [1] [2] phpstan/phpstan-symfony
- PHPStan\Rules\Traits\TraitAttributesRule [1]